Link Field and check box field in the Grid view


/ Published in: ASP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <asp:GridView ID="GridView1" runat="server" autogeneratecolumns="false">
  2. <Columns>
  3. <asp:TemplateField HeaderText="TITLE">
  4. <ItemTemplate>
  5. <asp:LinkButton ID="lnkTitle" runat="server" Text='<%#Bind("TITLE") %>' CommandArgument='<%#Eval("ID")%>' onclick="lnkTitle_Click"/>
  6. </ItemTemplate>
  7. </asp:TemplateField>
  8. <asp:boundfield datafield="TITLE" headertext="TITLE"/>
  9. <asp:boundfield datafield="DESCRIPTION" headertext="DESCRIPTION"/>
  10. <asp:boundfield datafield="OWNER" headertext="OWNER"/>
  11. <asp:TemplateField HeaderText="Enabled">
  12. <ItemTemplate>
  13. <asp:CheckBox ID="chkEnabled" runat="server" Checked='<%# Eval("ENABLED") %>' />
  14. </ItemTemplate>
  15. </asp:TemplateField>
  16. </Columns>
  17. </asp:GridView>
  18.  
  19.  
  20.  
  21. //////////////////////////////////Code Behind
  22.  
  23.  
  24. protected void lnkTitle_Click(object sender, EventArgs e)
  25. {
  26.  
  27.  
  28. LinkButton lnkTiltle = (LinkButton) sender;
  29. Int32 ID=Convert.ToInt32(lnkTiltle.CommandArgument.ToString());
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.