ImageButton not firing ItemCommand event for the datagrid

Discussion in 'ASP .Net Datagrid Control' started by John, Aug 4, 2005.

  1. John

    John Guest

    Hey guys, i have 2 datagrids on a page that are shown and hidden using
    component one tabs and topic bars and stuff like that. the original grid
    works fine, but the second grid i added works just like it should except that
    when you click one of the 4 image buttons( not all of them are visible at
    the same time and 2 call javascript confirm functions onClick) they dont fire
    the ItemCommand event of my datagrid they just postback and dont do anything
    except display the confirm boxes. i have looked in the code that .NET
    InitializeComonent function and the first dg is listed but the second is not.
    the itemdatabound fucntion on the second grid fires and works, but its not
    listed here and even when they are listed(i added them once) it didnt change
    anything ItemDataBound worked perfectly, but ItemCommand get ignored. in the
    datagrid delceration in the html i do assign these funciton to their
    respective events.

    thanks for all the help

    ItemCommand Function:
    protected void dgEmailResults_ItemCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    Trace.Write("e.CommandName=" + e.CommandName);
    Trace.Write("e.CommandArgument=" + e.CommandArgument);

    // get the item's broadcastID
    int broadcastID = int.Parse(e.CommandArgument.ToString());

    // fire the appropriate method
    switch (e.CommandName)
    {
    case "Resume":
    resumeEmailBroadcast(broadcastID);
    break;
    case "Pause":
    pauseEmailBroadcast(broadcastID);
    break;
    case "Stop":
    killEmailBroadcast(broadcastID);
    break;
    case "Retry":
    retryEmailBroadcast(broadcastID);
    break;
    }

    // update the table
    bindGrid();
    }
    ItemDataBound:

    protected void dgEmailResults_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    // make sure this is an Item or an AlternatingItem row
    ListItemType myType = (ListItemType)e.Item.ItemType;
    Trace.Write("itemdatabound");
    if (myType == ListItemType.Item || myType == ListItemType.AlternatingItem)
    {

    // get instances of each button
    ImageButton btnEmailStop =
    (ImageButton)e.Item.FindControl("btnEmailStop");
    ImageButton btnEmailRetry =
    (ImageButton)e.Item.FindControl("btnEmailRetry");
    ImageButton btnEmailPause =
    (ImageButton)e.Item.FindControl("btnEmailPause");
    ImageButton btnEmailResume =
    (ImageButton)e.Item.FindControl("btnEmailResume");
    // add the 'onclick' client-side handlers to each button
    btnEmailStop.Attributes.Add("onclick", "return confirmKill();");
    btnEmailRetry.Attributes.Add("onclick", "return confirmRetry();");

    // turn all buttons off, then turn the appropriate buttons on
    btnEmailStop.Visible = false;
    btnEmailRetry.Visible = false;
    btnEmailPause.Visible = false;
    btnEmailResume.Visible = false;

    switch (int.Parse(DataBinder.Eval(e.Item.DataItem,
    "EMailBroadcastStatusId").ToString()))
    {
    case 0:
    btnEmailResume.Visible = true;
    btnEmailStop.Visible = true;
    break;
    case 1:
    case 2:
    btnEmailStop.Visible = true;
    btnEmailPause.Visible = true;
    break;
    default:
    btnEmailRetry.Visible = true;
    break;
    }//end switch
    }//end if
    }//end item databound
    John, Aug 4, 2005
    #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. =?Utf-8?B?RGVlcGVzaA==?=

    Datagrid ItemCommand Event Not Firing

    =?Utf-8?B?RGVlcGVzaA==?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,793
    =?Utf-8?B?RGVlcGVzaA==?=
    Oct 6, 2005
  2. =?Utf-8?B?ZGFuYw==?=

    DataGrid ItemCommand event not firing if not first page

    =?Utf-8?B?ZGFuYw==?=, Oct 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,142
    =?Utf-8?B?ZGFuYw==?=
    Oct 26, 2005
  3. Andy
    Replies:
    0
    Views:
    413
  4. Nathan Sokalski
    Replies:
    2
    Views:
    999
    Nathan Sokalski
    Nov 17, 2007
  5. PD
    Replies:
    0
    Views:
    370
Loading...

Share This Page