Search code examples
asp.netgridviewrowcommand

GridView RowCommand Not Firing at all for image button


Iam trying to fire rowCommand event on Image button click in my GridView. The GridView is inside Update Panel. But after trying all the means like:

  • EnableViewState,

  • Binding Grid on IsPostback,

Iam not able to get the exact reason.

Please find the code below:

 <asp:GridView ID="grdReport" runat="Server" CellPadding="0" Height="50%" HeaderStyle-CssClass="dataHeadStyle"
               OnPageIndexChanging="grdReport_PageIndexChanging" CssClass="lblStyle" AutoGenerateColumns="false" ShowHeader="true" ShowFooter="false"
               GridLines="Both" Width="100%" AlternatingRowStyle-CssClass="dataAltRowStyle"
               RowStyle-CssClass="dataItemsStyle2" DataKeyNames="TRAINING_ID" AllowPaging="true"
               PageSize="7" OnRowCommand="grdReport_RowCommand" OnRowDataBound="grdReport_RowDataBound" EnableViewState="true">

      <Columns>
            <asp:TemplateField HeaderText="Select" ItemStyle-CssClass="dataItemsStyle1">
                <ItemStyle HorizontalAlign="Center" Width="7%" />
                <HeaderStyle HorizontalAlign="Center" />
                <ItemTemplate>
                      <asp:ImageButton ID="ImgSelect" runat="server" CausesValidation="false" ImageUrl="~/Images/edit_icon.gif"
                                  CommandName="select" CommandArgument='<%# Eval("TRAINING_NAME")+","+ Eval("TRAINING_DESCRIPTION")+","+ Eval("TRAINING_DUE_DATE")%> '/>
                </ItemTemplate>
                <ControlStyle CssClass="ViewHand" />
           </asp:TemplateField>



protected void grdReport_RowCommand(object sender, GridViewCommandEventArgs e)
{
    try
    {
        string TrainingInfo = e.CommandArgument.ToString();


        MS_RITBL objBL = new MS_RITBL();
        //string Mst_Report_Id = string.Empty;
        //string Report_ID = string.Empty;
        //string IsReportLocked = string.Empty;
        //string lockedBy = string.Empty;
        //string due_date = string.Empty;
        if (e.CommandName == "select")
        {
            //lnkReportID.Enabled = false;
            string strMst_Report_Id = Convert.ToString(e.CommandArgument);
            //Session["MST_REPORT_ID"] = Mst_Report_Id;
            //SetToolTip();
        }

    }
    catch (Exception)
    {

        throw;
    }
}

Please Help.


Solution

  • Guys the problem was that labels inside ItemTemplate were having same id accidently so event was blocking up.

    Thanks