DataGrid and custom buttons

O

ool

Hello,

I have a DataGrid with a few columns, I would like to add a column with a
button, which will be displayed only if row contatins certain data.
I also would like to define a special action after clicking on tkis button.

To create a button I used ItemCreated event for DataGrid:

private void DataGrid1_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
{
string sMyString=

((System.Data.DataRowView)(((System.Object)(((System.Web.UI.WebControls.Data
GridItem)((e.Item))).DataItem)))).Row.ItemArray[1].ToString();
if ( sMyString="Certain Value")
{
System.Web.UI.WebControls.Button bt = new
System.Web.UI.WebControls.Button();
bt.Click +=new EventHandler(this.bt_Click);
bt.Text="My Text";
e.Item.Cells[3].Controls.Add(bt);
}
}
}

The button is properly created and displayed but Event Handler function
bt_Click is never invoked
private void bt_Click(object sender, EventArgs e)
{
//My Action

}


Could someone help me solve this problem? I would be very grateful.

Regards

Tomasz
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top