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
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.
Re: ASP.NET VB in HTML body
Could you show me the code you use to populate your datatable.
Cheers
DJ
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)
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.
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
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?
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
Re: ASP.NET VB in HTML body
Re: ASP.NET VB in HTML body
how do i do a remove_item? (to delete that datarow?)