Thursday, 8 July 2010

FINDING OTHER CONTROLS IN SAME GRIDVIEW ROW FROM THE EVENT METHOD OF A CONTROL

  1. <asp:GridView ID="GridView1" runat="server"
  2. AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand">
  3. <Columns>
  4. <asp:BoundField DataField="CategoryID"
  5. HeaderText="CategoryID" />
  6. <asp:BoundField DataField="CategoryName"
  7. HeaderText="CategoryName" />
  8. <asp:TemplateField HeaderText="Select">
  9. <ItemTemplate>
  10. <asp:CheckBox ID="CheckBox1"
  11. AutoPostBack="true" runat="server"
  12. OnCheckedChanged="CheckBox1_CheckedChanged1" />
  13. ItemTemplate>
  14. asp:TemplateField>
  15. Columns>
  16. asp:GridView>
  17. And the code behind:
  18. protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
  19. {
  20. CheckBox checkbox = (CheckBox)sender;
  21. GridViewRow row = (GridViewRow) checkbox.NamingContainer;
  22. Response.Write(row.Cells[0].Text);
  23. }

No comments:

Post a Comment