<asp:table...> and PostBack

G

Guest

Hey guys, I'm having a problem and need some help. I have an <asp:table ...>
in my web page, and this table has 2 rows, the first being a header row, and
the second row containing an <asp:button> to add rows to the table. Well,
when I add the first row it shows up, but if I try to add any more rows, the
one I added + the rest of them all disappear. I tried saving the table to a
Session variable, but that didn't work. I'm not really sure what is going
on, but any help would be appreciated.

CODE:
ASP:
<asp:table runat="server" id="InvolvementTable">
<asp:tablerow id="row1">
<asp:tableheadercell>Name</asp:tableheadercell>
<asp:tableheadercell>Details</asp:tableheadercell>
</asp:tablerow>
<asp:tablerow>
<asp:tablecell columnspan="2" horizontalalign="Center">
<asp:button runat="server" id="addRowButton" text="Add
Row"></asp:button>
</asp:tablecell>
</asp:tablerow>
</asp:table>

C#:

System.Web.UI.WebControls.TableRow r = new TableRow();
System.Web.UI.WebControls.TableCell c = new TableCell();
c.Text = "<input type=\"text\" size=\"30\" id=\"personInvolved" + count +
"\" />";
c.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
r.Cells.Add(c);
c = new TableCell();
c.Text = "<input type=\"text\" size=\"30\" id=\"personInvolvedDesc" + count
+ "\" />";
c.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
r.Cells.Add(c);
InvolvementTable.Rows.AddAt(InvolvementTable.Rows.Count-1, r);
Session["RowCount"] = ++count;
Session["InvolveTable"] = InvolvementTable;
 
O

Otis Mukinfus

Hey guys, I'm having a problem and need some help. I have an <asp:table ...>
in my web page, and this table has 2 rows, the first being a header row, and
the second row containing an <asp:button> to add rows to the table. Well,
when I add the first row it shows up, but if I try to add any more rows, the
one I added + the rest of them all disappear. I tried saving the table to a
Session variable, but that didn't work. I'm not really sure what is going
on, but any help would be appreciated.

CODE:
ASP:
<asp:table runat="server" id="InvolvementTable">
<asp:tablerow id="row1">
<asp:tableheadercell>Name</asp:tableheadercell>
<asp:tableheadercell>Details</asp:tableheadercell>
</asp:tablerow>
<asp:tablerow>
<asp:tablecell columnspan="2" horizontalalign="Center">
<asp:button runat="server" id="addRowButton" text="Add
Row"></asp:button>
</asp:tablecell>
</asp:tablerow>
</asp:table>

C#:

System.Web.UI.WebControls.TableRow r = new TableRow();
System.Web.UI.WebControls.TableCell c = new TableCell();
c.Text = "<input type=\"text\" size=\"30\" id=\"personInvolved" + count +
"\" />";
c.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
r.Cells.Add(c);
c = new TableCell();
c.Text = "<input type=\"text\" size=\"30\" id=\"personInvolvedDesc" + count
+ "\" />";
c.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
r.Cells.Add(c);
InvolvementTable.Rows.AddAt(InvolvementTable.Rows.Count-1, r);
Session["RowCount"] = ++count;
Session["InvolveTable"] = InvolvementTable;

Hello Drew,

I'm making a wild guess here, but are you leaving the cells on the row you add
empty? If you are they won't display. I'm assuming (perhaps in error) that you
are trying to display empty rows. If that is correct you will have to give a
cell on each row some content or the row will not be visible. I think I've
solved that problem by putting a space in one of the cells on a row. If you do
that you will have to trim anything you take out of that cell later.

Hope that tickles an idea somewhere.

Otis
 

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