J
John Bankhead
Top of page: Listbox and button. Listbox contains a list of products.
Button says "Load". Beneath both is a datagrid. In the datagrid, 25 columns
contain text and one of the columns contains a textbox or button depending on
the nature of the account. Clicking a button in this column causes a
round-trip to the server and another control to appear on top of the datagrid
for more detailed info.
Here is the problem: Loading the datagrid with a product which shows buttons
will cause that detailed control to appear for the datagrid row to have a
button in that column. No clicking on the button is necessary. How is the
command event for that button being invoked?
All of the datagrid buttons are created in the ItemDataBound event for the
datagrid. Their command events are attached to "private void
btnTier_Command(object sender, CommandEventArgs e)" and each carries the id
of its particular account in the CommandArgument attribute.
from ItemDataBound event:
if(e.Item.Cells[tieredColumn].Text=="TIERED"){
b = new Button();
b.ID = "revprice_" + Counter.ToString();
b.Text = e.Item.Cells[RevPriceCol].Text;
b.Width = Unit.Pixel(58);
b.BackColor = bModded? Color.FromArgb(220, 248, 217) : Color.LightGray;
b.ForeColor = bException? Color.Red : Color.Black;
b.CommandArgument = e.Item.Cells[AcctCol].Text;
b.CommandName = "btnTier";
b.Command+=new CommandEventHandler(btnTier_Command);
b.Enabled = bExclude;
e.Item.Cells[RevPriceCol].Controls.Add(b);
}
-------------------
private void btnTier_Command(object sender, CommandEventArgs e){
int acct = Convert.ToInt32(e.CommandArgument);
AccountTier tier = new AccountTier(acct, Decision, dstConnectionString);
tier.ID = "tiered";
tier.Attributes.Add("style",
"z-index:300;position:absolute;top:125;left:100;");
this.Controls.Add(tier);
}
Button says "Load". Beneath both is a datagrid. In the datagrid, 25 columns
contain text and one of the columns contains a textbox or button depending on
the nature of the account. Clicking a button in this column causes a
round-trip to the server and another control to appear on top of the datagrid
for more detailed info.
Here is the problem: Loading the datagrid with a product which shows buttons
will cause that detailed control to appear for the datagrid row to have a
button in that column. No clicking on the button is necessary. How is the
command event for that button being invoked?
All of the datagrid buttons are created in the ItemDataBound event for the
datagrid. Their command events are attached to "private void
btnTier_Command(object sender, CommandEventArgs e)" and each carries the id
of its particular account in the CommandArgument attribute.
from ItemDataBound event:
if(e.Item.Cells[tieredColumn].Text=="TIERED"){
b = new Button();
b.ID = "revprice_" + Counter.ToString();
b.Text = e.Item.Cells[RevPriceCol].Text;
b.Width = Unit.Pixel(58);
b.BackColor = bModded? Color.FromArgb(220, 248, 217) : Color.LightGray;
b.ForeColor = bException? Color.Red : Color.Black;
b.CommandArgument = e.Item.Cells[AcctCol].Text;
b.CommandName = "btnTier";
b.Command+=new CommandEventHandler(btnTier_Command);
b.Enabled = bExclude;
e.Item.Cells[RevPriceCol].Controls.Add(b);
}
-------------------
private void btnTier_Command(object sender, CommandEventArgs e){
int acct = Convert.ToInt32(e.CommandArgument);
AccountTier tier = new AccountTier(acct, Decision, dstConnectionString);
tier.ID = "tiered";
tier.Attributes.Add("style",
"z-index:300;position:absolute;top:125;left:100;");
this.Controls.Add(tier);
}