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

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. Flare
    Replies:
    0
    Views:
    430
    Flare
    Aug 26, 2003
  2. Roger
    Replies:
    1
    Views:
    820
    GreggTB
    May 20, 2005
  3. =?Utf-8?B?QmVu?=

    Image Buttons/Buttons not responding

    =?Utf-8?B?QmVu?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    597
    Teemu Keiski
    Jul 6, 2005
  4. Jeremy Jones

    Datagrid Nav buttons and numeric buttons

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

    Dynamically creating buttons in custom datagrid control

    lawrence, Nov 18, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    205
    lawrence
    Nov 18, 2003
  7. Baburaj

    Access the buttons in the datagrid within another datagrid

    Baburaj, Mar 12, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    350
    Baburaj
    Mar 12, 2005
  8. Flare
    Replies:
    0
    Views:
    204
    Flare
    Aug 26, 2003
Loading...