Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends...!!

I have some problem in my Program , that is Link Button is not fire in grid View ,
so pls advice ...

code below

XML
<asp:GridView runat="server" ID="gridview1"  AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" >
    <rowstyle backcolor="#F7F6F3" forecolor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Check Box">
<ItemTemplate>
     <asp:CheckBox runat="server" ID="chk_check" />

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Business_Partner">
<ItemTemplate>
      <asp:Label runat="server" ID="lbl_Business_Partner" Text='<%#Eval("Business_Partner")%>'></asp:Label>
 </ItemTemplate>


</asp:TemplateField>
<asp:TemplateField HeaderText="Company_Name">
<ItemTemplate>
<asp:LinkButton runat="server" ID="link_button" Text="welcome" OnClick="link_button_Click"></asp:LinkButton>
<%--<asp:LinkButton runat="server" ID="lnkView" Text='<%#Eval("Company_Name")%>' OnClick="lnkView_Click"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Contact_Personname"><ItemTemplate>
    <asp:Label runat="server" ID="lbl_Contact_Personname" Text='<%#Eval("Contact_Personname")%>'></asp:Label>

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Designation"><ItemTemplate>

    <asp:Label runat="server" ID="lbl_Designation" Text='<%#Eval("Designation")%>'></asp:Label>

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address"><ItemTemplate>

    <asp:Label runat="server" ID="lbl_Designation" Text='<%#Eval("Address")%>'></asp:Label>

</ItemTemplate>
</asp:TemplateField>
</Columns>
    <RowStyle BackColor="#F7F6F3" Font-Size="18px"  ForeColor="#333333" />
    <footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White" />
    <pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center" />
    <selectedrowstyle backcolor="#E2DED6"  font-bold="True" forecolor="#333333" />
    <headerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White" />
    <editrowstyle backcolor="#999999" />
    <alternatingrowstyle backcolor="White" forecolor="#284775" />
</asp:GridView>



aspx.cs

link button click event

C#
protected void link_button_Click(object sender, EventArgs e)
   {

   }
Posted
Comments
Thanks7872 19-Sep-14 9:17am    
If you copied code from this : http://www.dotnetbull.com/2013/05/how-to-handle-click-event-of-linkbutton.html, than i think there is something you missed to copy.
[no name] 19-Sep-14 9:18am    
have tested with debugger and is there any client validation in design side

1 solution

1. You will have to add a commandname="View" and commandargument to your link button.
2. After that add the "OnRowCommand" event for the gridview.
3. In OnRowCommand event write what ever you wanted to write in linkbutton click event.

C#
protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == "View")
  {
    //your code
  }
}


If you dont understand what I am trying to say kindly go through the link provided below.
http://stackoverflow.com/questions/23180346/click-event-of-link-button-inside-a-gridview-not-working-in-a-web-page-asp-net[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900