K
Kevin Blount
I'd like to create a script that adds rows to an existing table, which
has a header and footer row. The new row should be added as the last
row BEFORE the footer.
Here's what I have, though it doesn't work as I require..
in the .aspx
in my .cs
The issue is that while this script does insert a TableRow before the
footer the first time, the second time I try to add a row, it
overwrites the first, i.e. the itemListTable.Rows.Count value does not
increase when I add a new row, so each time this method is called, the
row count is 2, the initial header and footer
I also tried other ideas, such as my own count of rows added, but
eventually my count goes outside of the acceptable values defined by
the RowsCollection max value (2).
Is there a way to either force an update of the Rows.Count for each
added row, or a better wya of doing this? The end result must be a
method of adding an indeterminate number of new rows, BEFORE the
footer and after the header.
Thanks in advance
has a header and footer row. The new row should be added as the last
row BEFORE the footer.
Here's what I have, though it doesn't work as I require..
in the .aspx
Code:
01: <asp:Table ID="itemListTable" runat="server">
02: <asp:TableHeaderRow ID="itemListTableHeader" runat="server" >
03: <asp:TableCell runat="server">PROJECT</asp:TableCell>
04: <asp:TableCell runat="server">ACTIVITY</asp:TableCell>
05: </asp:TableHeaderRow>
06:
07: <asp:TableFooterRow ID="itemListTableFooter" runat="server">
08: <asp:TableCell runat="server" ColumnSpan="2"
HorizontalAlign="Right">TOTAL HOURS</asp:TableCell>
09: <asp:TableCell runat="server" ><asp:Label ID="totals"
runat="server" ></asp:Label></asp:TableCell>
10: <asp:TableCell runat="server" ></asp:TableCell>
11: </asp:TableFooterRow>
12: </asp:Table>
13: <asp:Button ID="itemSubmit" runat="server" Text="duh" />
in my .cs
Code:
01: protected void itemSubmit_Click(object sender, EventArgs e) {
02: int rowCount = itemListTable.Rows.Count;
03: TableRow newRow = new TableRow();
04:
05: TableCell projectCell = new TableCell();
06: projectCell.Text = itemProject.SelectedItem.Text;
07: newRow.Cells.Add(projectCell);
08:
09: TableCell activityCell = new TableCell();
10: activityCell.Text = itemActivity.SelectedItem.Text;
11: newRow.Cells.Add(activityCell);
12:
13: itemListTable.Rows.AddAt((rowCount - 1), newRow);
14: }
The issue is that while this script does insert a TableRow before the
footer the first time, the second time I try to add a row, it
overwrites the first, i.e. the itemListTable.Rows.Count value does not
increase when I add a new row, so each time this method is called, the
row count is 2, the initial header and footer
I also tried other ideas, such as my own count of rows added, but
eventually my count goes outside of the acceptable values defined by
the RowsCollection max value (2).
Is there a way to either force an update of the Rows.Count for each
added row, or a better wya of doing this? The end result must be a
method of adding an indeterminate number of new rows, BEFORE the
footer and after the header.
Thanks in advance