Thursday 22 August 2013

HTML Table in VB.Net back end code

HTML Table in VB.Net back end code

I have a table that I have created in the VB.net code behind. I have a
connection to a database and it returns records to put into my html table.
What I'm having issues with is I want to have 5 cells per row and an
unlimited amount of rows. Everytime I try and do something that only has
the 5 cells per row it's returning something that I don't need. Please
help!! Here is the code that I'm using.
Protected Sub LoadProducts() Dim con5 As New SqlConnection Dim cmd5 As New
SqlCommand Dim index As Integer = 0
con5.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")
con5.Open()
cmd5.Connection = con5
cmd5.CommandType = CommandType.StoredProcedure
cmd5.CommandText = "ProductTypesSearch"
Dim dt1 As New DataSet
cmd5.Parameters.Add(New SqlParameter("ProductID",
SqlDbType.Int)).Value = 1
cmd5.Parameters.Add(New SqlParameter("CollectionID",
SqlDbType.Int)).Value = 2
Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd5)
da1.Fill(dt1)
Dim cell As HtmlTableCell
Dim row As HtmlTableRow
Dim table1 As New HtmlTable
row = New HtmlTableRow()
Dim numells As Integer = 6
dv = New DataView(dt1.Tables(0))
Dim tablestring = ""
If dv.Table.Rows.Count > 0 Then
For Each dr As DataRowView In dv
Dim crossover As String = dr("CrossoverID").ToString()
Dim picid As String = dr("Description").ToString()
Dim picdescrip As String = dr("DesignColor").ToString()
cell = New HtmlTableCell()
' cell.InnerHtml = "<table style='width:100%'><tr><td
colspan='4'><img src='/Images/splashpage.jpg' width='1000'
height='100'></td></tr>"
'For i As Integer = 1 To 1
For j As Integer = 0 To numells - 1
cell.InnerHtml = "<table width-'100%'>"
cell.InnerHtml += "<tr><td><div class='product'><td><a
href='ProductBreakdown2.aspx?p=" + crossover + "'</a>"
cell.InnerHtml += "<div class='product'><img
src='Images/WebsiteProductImages/" + picid + ".png'
width='100' height='100'>"
cell.InnerHtml += "<div class = 'test'>" + picdescrip
cell.InnerHtml += "</td></tr></div></div></table>"
' Add the cell to the current row.
row.Cells.Add(cell)
Next
' table1.Rows.Add(row)
Next
' Next
'' Add the row to the table.
'' Next
'' Add the table to the page.
Me.Controls.Add(table1)
End If
End Sub

No comments:

Post a Comment