Table Rows

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
 
L

Looch

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";
}
}
 
L

Looch

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

Andrew Morton

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top