DataGrid and custom buttons

Discussion in 'ASP .Net' started by ool, Feb 17, 2004.

  1. ool

    ool Guest

    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
    ool, Feb 17, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Srinivasa Reddy K Ganji

    Re: Custom image buttons in Datagrid

    Srinivasa Reddy K Ganji, Jul 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    411
    Srinivasa Reddy K Ganji
    Jul 25, 2003
  2. Flare
    Replies:
    0
    Views:
    358
    Flare
    Aug 26, 2003
  3. Jeremy Jones

    Datagrid Nav buttons and numeric buttons

    Jeremy Jones, Mar 21, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    615
    Masudur
    Mar 22, 2007
  4. Jonathan N. Little
    Replies:
    3
    Views:
    521
    Andy Dingley
    Apr 2, 2007
  5. lawrence

    Dynamically creating buttons in custom datagrid control

    lawrence, Nov 18, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    130
    lawrence
    Nov 18, 2003
Loading...

Share This Page