Table Rows

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

All,

I can only add one row to a Table control. Is there a property that
restricts adding multiple rows? I've tried several different ways.
I've gotten to the point where I can add the information I need for
the second row but it only replaces the original info from the first
row, resulting in still only one row.

Thanks
 
Here's the code I'm using, the 'else' statement below never gets ran
regardlesss how many times the cmdAdd button is clicked.

protected void Page_Load(object sender, EventArgs e)
{
ddlQuantity.Items.Clear();
ddlItem.Items.Clear();
ddlQuantity.Items.Add("1");
ddlQuantity.Items.Add("2");
ddlQuantity.Items.Add("3");
ddlQuantity.Items.Add("4");
ddlItem.Items.Add("Test");
ddlItem.Items.Add("Test2");
Session.Add("RowCount", (int)ItemTable.Rows.Count);
}
protected void cmdAdd_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(Session["RowCount"]) == 0) //For the first
time cmdAdd is clicked
{
row.ID = "row" + ItemTable.Rows.Count.ToString();
cell.Width = 343;
cell.ID = "cell" + ItemTable.Rows.Count.ToString();
cell2.Width = 125;
cell2.ID = "cell2" + ItemTable.Rows.Count.ToString();
cell2.HorizontalAlign = HorizontalAlign.Center;

ItemTable.Rows.Add(row);
row.Cells.Add(cell);
row.Cells.Add(cell2);
ItemTable.Rows[0].Cells[0].Text = ddlItem.Text;
ItemTable.Rows[0].Cells[1].Text = ddlQuantity.Text;

ItemsToOrder items = new ItemsToOrder();
items.ItemName = ddlItem.Text;
items.Quantity = ddlQuantity.Text;
Session.Add("ItemOrder", items);

Session["RowCount"] = ItemTable.Rows.Count;
}
else //For every other time the button is clicked
{
txtPendingShip.Text = "Test";
}
}
 
I was going to address that once I got past the row adding hurdle,
I've been stuck on that for about a day now...
 
Looch said:
ItemTable.Rows.Add(row);

Try

ItemTable.Rows.Add(row.Clone);

otherwise you're always adding a /reference/ to the same variable rather
than the data in that variable.

Andrew
 
Back
Top