Populate Table using Dataset

J

Junior

Hi All,

I haven't got a response for this question lately and i really need to
get this done ASAP.

I have a .aspx page that has table two column four rows on it.
1. How do i use codebehind C# to populate the HTML table?
2. How do i pull some figures from the second column and add them up in
the Total field.

here is a snipplet of the table:
<body MS_POSITIONING="GridLayout">
<form id=Form1 method=post runat="server">
<table>
<tr>
<td>Funds to Load</td>
<td><input style="WIDTH: 157px"
onchange=calculateTotal name=funds></td></tr>
<tr>
<td style="HEIGHT: 25px">Administrative Charge</td>
<td style="HEIGHT: 25px"><input id=admin
style="WIDTH: 157px; HEIGHT: 22px" disabled readOnly size=21
value=2%
</td></tr>
<tr>
<td>Minimum Adjustment</td>
<td><input id=minimum style="WIDTH: 157px" disabled readOnly
value=$1000></td></tr>
<tr>
<td style="HEIGHT: 27px">Total Funds Required</td>
</td></tr>
<tr>
<td align=center colSpan=2><input type=submit value="Submit
Request"></td></tr></table>
<asp:Label id=Label1 style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 216px" runat="server" Width="168px" Height="24px">Funds
to Load</asp:Label>
<asp:Label id=Label2 style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 240px" runat="server" Width="176px"
Height="24px">Administrative Charge</asp:Label>
<asp:Label id=Label3 style="Z-INDEX: 103; LEFT: 16px; POSITION:
absolute; TOP: 264px" runat="server" Width="168px"
Height="24px">Minimum Adjustment</asp:Label>
<asp:Label id=Label4 style="Z-INDEX: 104; LEFT: 16px; POSITION:
absolute; TOP: 288px" runat="server" Width="168px" Height="16px">Total
Funds Required</asp:Label>
<asp:TextBox id=txtFundsToLoad style="Z-INDEX: 105; LEFT: 192px;
POSITION: absolute; TOP: 208px" runat="server" Width="161"
Height="24"></asp:TextBox>
<asp:TextBox id=txtAdmin style="Z-INDEX: 106; LEFT: 192px; POSITION:
absolute; TOP: 232px" runat="server" Width="161px" Height="24px"
ReadOnly="True" BackColor="#E0E0E0"></asp:TextBox>
<asp:TextBox id=txtMin style="Z-INDEX: 107; LEFT: 192px; POSITION:
absolute; TOP: 256px" runat="server" Width="161px"
Height="24px"></asp:TextBox>
<asp:TextBox id=txtTotal style="Z-INDEX: 108; LEFT: 192px; POSITION:
absolute; TOP: 280px" runat="server" Width="161px" Height="24px"
ReadOnly="True" BackColor="#E0E0E0"></asp:TextBox>
<asp:Button id=Button1 style="Z-INDEX: 109; LEFT: 104px; POSITION:
absolute; TOP: 317px" runat="server" Width="144px" Text="Submit
Request" Height="25px"></asp:Button></form>
</body>


Someone please help.
 
G

Guest

First, you'll have to make your table a Server Control by adding a
runat="server" and an id=someTableName to the declaration. Then you can
access the table's Rows and Cells programmatically like this:

someTableName.Rows[0].Cells[1].InnerText = "abcde";

You would have to iterate through your list of data, keeping up with your
totals.

That said, there are a few better solutions for many circumstances:

If you have to use a table, read up on System.Web.UI.WebControls.Table.
That table is completely programmable in code with a much more complete set
of properties and methods.

Even better would be to use a DataGrid or Repeater because you can do data
binding to them. Then in your OnItemDataBound handler, you can sum your
totals and if the Item.ItemType is ListItemType.Footer, you add your text to
Item.Cells[x] where x is the member of the Cells array that you want the
total written to.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top