• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

how to dynamically build and fill a table

I am using asp.net

I want to retrieve some data, then dynamically build a table based on the data returned.

I know I can easily use a gridview for this purpose. But I want to learn how to do this.

Can someone give me some suggestions on how to approach this.

My SQ!L query would look similar to this one.

SELECT
ITEMS.FULL_NAME as 'Item#',
ITEMS.SALESDESCRIPTION as 'Description',
ITEMS.MANUFACTURER as 'Mfg',
ITEM_LOCATION_MAP.ON_HAND_COUNT as 'Total',
ITEMS.ITEM_CLASS as 'Class',
Notes_User.Comments,
ITEMS.picture
FROM Administrator.ITEMS
LEFT OUTER JOIN Administrator.ITEM_LOCATION_MAP ON Administrator.ITEM_LOCATION_MAP.ITEM_ID = Administrator.ITEMS.ITEM_ID
Left join notes_user on notes_user.item_id = items.item_id

where Administrator.Items.IsInactive = 'No' and items.name like '7402%'
0
Wildone63
Asked:
Wildone63
  • 2
2 Solutions
 
Tom BeckCommented:
Write your data to a DataTable then use a StringBuilder to build your HTML markup, adding the data items row by row in a loop through the DataTable. Insert your data items where necessary in the table. When the HTML is built, paste it to the web page using a Placeholder in which you add your StringBuilder object as a Literal control.
0
 
Wildone63Author Commented:
Well I am pretty sure I understand....

I know how to use SB and I can get the data into a table, it is the looping that I am not sure of.

Here is my code to build my table.
        Dim myquery1 As String = "SELECT Items.Item_ID, Items.Full_Name, Items.Manufacturer, Items.MPN, Items.Name, Items.SalesDescription, Items.Item_Class, Items.Item_Status, Items.Picture, Items.Item_Belongs_To_ID FROM Administrator.ITEMS WHERE Items.Full_Name Like " + "'" + MyItem + "%" + "'" + """"""
        Dim mycs1 As String = "Dsn=NS.com;uid=user@mynet.net;pwd=password"
        Dim dbadp1 As New OdbcDataAdapter(myquery1, mycs1)
        Dim dTable1 As New DataTable
        dbadp1.Fill(dTable1)

Can you help me with the loop part please?

Thanks
0
 
djon2003Commented:
Here is a code to go through your datable and create an html table.
Dim sb as New StringBuilder()

sb.append("<table>")

For Each curRow as DataRow in dTable1.Rows
  sb.append("<tr>")
  For Each curCol as DataColumn in dTable1.Columns
    sb.append("<td>").append(curRow(curCol.Name)).append("</td>")
  Next
  sb.append("</tr>")
Next

sb.append("</table>")

Open in new window

0
 
Wildone63Author Commented:
Thank you both!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now