Search code examples
c#asp.netsql-servergridviewautopostback

gridview rowcommand not firing in Asp.Net


I am creating ASP.net website I want to perform some action on two of gridview row command but that event is not firing on one of the web from. I have same thing in other page as well and it's working fine but I don't know Why it's not working for this page, please let me know if I am missing any thing or do I need to do something to make it work.

Page Load

protected void Page_Load(object sender, EventArgs e)
  {
if (!IsPostBack)
    {
        GridView1.DataSource = getData();
        GridView1.DataBind();
    }
}

Event

protected void GridView1_RowCommand1(object sender, GridViewCommandEventArgs e)
{
System.Diagnostics.Debug.WriteLine("command click:" + e.CommandName);
}

Designing

  <asp:GridView ID="GridView1" runat="server" CssClass="myGridClass"
      ShowHeaderWhenEmpty="True" EmptyDataText="No records Found"
     AutoGenerateColumns="False" Width="85%" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="Vertical" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="GridView1_RowCommand1">
    <AlternatingRowStyle CssClass="alt" BackColor="White"></AlternatingRowStyle>
    <Columns>
                             <asp:TemplateField HeaderStyle-CssClass="gridheader">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton2" CommandName="DownloadImage" CommandArgument='<%# Eval("MIRImage")%>' runat="server">Download</asp:LinkButton>
                                    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
</asp:GridView>

Solution

  • For now CausesValidation="false" into linkbutton did the job.

    can any one explain me about that