|
-
May 12th, 2005, 03:35 AM
#1
Thread Starter
Lively Member
ASP.NET VB in HTML body
Hi, I'm writing a .aspx in asp.net vb codes, i have
a datatable, however i can't seem to display
the individual field data of each records as i'm not
sure if i'm coding it correctly, please correct me!
help appreciated!
<BODY>
<% Dim i As Integer %>
<% For i = 0 to DataTable.Rows.Count - 1 %>
<% DataRow = DataTable.Rows(i) %>
<% DataRow.Item("ID") %> , <% DataRow.Item("Name") %> , <% DataRow.Item("Age") %>
<% Next %>
</BODY>
-
May 12th, 2005, 03:56 AM
#2
Frenzied Member
Re: ASP.NET VB in HTML body
You aren't really using ASP.NET as was intended - your coding is more like classic ASP.
Try using a repeater and databinding it to your DataTable.
Let me know if you need any more help.
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
May 12th, 2005, 06:00 AM
#3
Thread Starter
Lively Member
Re: ASP.NET VB in HTML body
yeah i wish to have more control.
can you show me some examples to display my datatable record
fields inside html body, thanks.
-
May 12th, 2005, 06:06 AM
#4
Frenzied Member
Re: ASP.NET VB in HTML body
Could you show me the code you use to populate your datatable.
Cheers
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
May 12th, 2005, 06:15 AM
#5
Thread Starter
Lively Member
Re: ASP.NET VB in HTML body
If Session("Table") Is Nothing Then
DataTable.Columns.Add("Code", GetType(String))
DataTable.Columns.Add("Product", GetType(String))
DataTable.Columns.Add("Quantity", GetType(Integer))
DataTable.Columns.Add("Cost", GetType(Decimal))
Session("Table") = DataTable
Else
DataTable = Session("Table")
End If
DataRow = DataTable.NewRow
DataRow("Code") = DataSet.FieldValue("product_id", nothing)
DataRow("Product") = DataSet.FieldValue("product_name", nothing)
DataRow("Quantity") = Int32.Parse(txtQuantity.Text)
DataRow("Cost") = Double.Parse(DataSet.FieldValue("product_cost", nothing))
DataTable.Rows.Add(DataRow)
-
May 12th, 2005, 06:18 AM
#6
Thread Starter
Lively Member
Re: ASP.NET VB in HTML body
the last 6 lines are actually in a button 'add' they will add
values of the product the user chooses, i tried using a
datagrid, it works perfectly, however i wish to have
more control to display the value not in a form of table
but at my own discrete.. thats why i chose for loop.
-
May 12th, 2005, 06:28 AM
#7
Frenzied Member
Re: ASP.NET VB in HTML body
OK gotcha.
Use the repeater control as it basically implements the loop you were writing within a control.
Within the ItemTemplate tags you can enter any HTML code you like to format the data.
To match your original example with the comma separated values you would do:
Code:
<asp:Repeater id="rptTest" runat="server">
<ItemTemplate>
<%# Container.DataItem("ID") %>, <%# Container.DataItem("Name") %>, <%# Container.DataItem("Age") %><br />
</ItemTemplate>
</asp:Repeater>
You must of course set the DataSource of the repeater to be the DataTable and call the repeater's DataBind method.
HTH
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
May 12th, 2005, 06:40 AM
#8
Thread Starter
Lively Member
Re: ASP.NET VB in HTML body
i tried setting <asp:Repeater id="rptTest" runat="server" DataSource='<%# DataTable.DefaultView %>'>
it tells me DataTable is not declared. how do i declare it?
-
May 12th, 2005, 06:44 AM
#9
Frenzied Member
Re: ASP.NET VB in HTML body
As the DataTable is created dynamically you'll need to databind it to the repeater just after it is created.
Code:
If Session("Table") Is Nothing Then
DataTable.Columns.Add("Code", GetType(String))
DataTable.Columns.Add("Product", GetType(String))
DataTable.Columns.Add("Quantity", GetType(Integer))
DataTable.Columns.Add("Cost", GetType(Decimal))
Session("Table") = DataTable
Else
DataTable = Session("Table")
End If
DataRow = DataTable.NewRow
DataRow("Code") = DataSet.FieldValue("product_id", nothing)
DataRow("Product") = DataSet.FieldValue("product_name", nothing)
DataRow("Quantity") = Int32.Parse(txtQuantity.Text)
DataRow("Cost") = Double.Parse(DataSet.FieldValue("product_cost", nothing))
DataTable.Rows.Add(DataRow)
rptTest.DataSource = DataTable.DefaultView
rptTest.DataBind()
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
May 12th, 2005, 06:53 AM
#10
Thread Starter
Lively Member
Re: ASP.NET VB in HTML body
-
May 12th, 2005, 07:19 AM
#11
Thread Starter
Lively Member
Re: ASP.NET VB in HTML body
how do i do a remove_item? (to delete that datarow?)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|