PC Review


Reply
Thread Tools Rate Thread

Adding TableRows

 
 
Kevin Blount
Guest
Posts: n/a
 
      26th Nov 2007
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
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
 
Reply With Quote
 
 
 
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      27th Nov 2007
Kevin,
This is really an ASP.NET newsgroup question, this is the C# language group
you've posted to. Try here:
http://msdn.microsoft.com/newsgroups...k.aspnet&fltr=

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com



"Kevin Blount" wrote:

> 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
>
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
>

 
Reply With Quote
 
Kevin Blount
Guest
Posts: n/a
 
      29th Nov 2007
On Nov 26, 6:15 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.com> wrote:
> Kevin,
> This is really an ASP.NET newsgroup question, this is the C# language group
> you've posted to. Try here:http://msdn.microsoft.com/newsgroups...guid=&sloc=en-...
>
> --Peter
> "Inside every large program, there is a small program trying to get out."http://www.eggheadcafe.comhttp://petesbloggerama.blogspot.comhttp://www.blogmetafinder.com
>
>
>
> "Kevin Blount" wrote:
> > 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
> >
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- Hide quoted text -

>
> - Show quoted text -


As ASP.NET can be written using C# I'm not sure why you think I
shouldn't post this question here. I dubt everyone using this
newsgroup is Windows only...
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bordering individual tablerows in a datatable Shak Microsoft ASP .NET 1 27th Sep 2005 11:26 AM
TableRows and Postback =?Utf-8?B?TWFyayBQYXJ0ZXI=?= Microsoft ASP .NET 2 4th May 2005 02:36 PM
How to dynamically add TableRows in asp.net? Jim Bancroft Microsoft ASP .NET 3 18th Dec 2004 12:13 AM
Need help please, Having trouble finding/adding users for purpose of granting permissions or adding them to groups in a win 2k domain on an XP workstation. rmalph@happy.days Microsoft Windows 2000 0 11th Oct 2004 11:37 PM
C#: order of TableRows in Table panik Microsoft ASP .NET 0 7th Nov 2003 03:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:53 AM.