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":
    case "Pause":
    case "Stop":
    case "Retry":

    // update the table

    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;
    if (myType == ListItemType.Item || myType == ListItemType.AlternatingItem)

    // get instances of each button
    ImageButton btnEmailStop =
    ImageButton btnEmailRetry =
    ImageButton btnEmailPause =
    ImageButton 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,
    case 0:
    btnEmailResume.Visible = true;
    btnEmailStop.Visible = true;
    case 1:
    case 2:
    btnEmailStop.Visible = true;
    btnEmailPause.Visible = true;
    btnEmailRetry.Visible = true;
    }//end switch
    }//end if
    }//end item databound
    John, Aug 4, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.