Saturday, March 31, 2012

Table Rows

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.
ThanksHow exactly are you trying to do this, in code, based on populating from
database?
(show us how you're trying to do it)
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Looch" <lucianoj2005@.yahoo.com> wrote in message
news:22db0303-349e-4e5e-a6f9-003c3cde7333@.62g2000hsn.googlegroups.com...
> 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";
}
}
Is there any reason you would need to rebuild the items in the dropdownlist
on every postback, and not surround it with an if/then/postback block?
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Looch" <lucianoj2005@.yahoo.com> wrote in message
news:d55f2313-88be-4980-83ab-b43430b9b674@.62g2000hsn.googlegroups.com...
> 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 wrote:
> 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

0 comments:

Post a Comment