Find Checkbox from GridView in Content Page/Master Page
How to find a control from GridView which resides in Content Page.
Here the example using to find the CheckBox, hope this will help you all...
.aspx code
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkID" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
|
codebehind
Dim ChkSel As New CheckBox Dim CellValue As New StringCollection Dim tmpGV As New GridView tmpGV = FindControlRecursive(Page.Master, "GridView1") For i = 0 To tmpGV.Rows.Count - 1 ChkSel = DirectCast(DirectCast(tmpGV.Rows(i), GridViewRow).Cells(0), TableCell).Controls(1) If ChkSel.Checked = True Then CellValue.Add(DirectCast(tmpGV.Rows(i), GridViewRow).Cells(1).Text) End If Next private Control FindControlRecursive(Control root, string id) { if (root.ID == id) { return root; } foreach (Control c in root.Controls) { Control t = FindControlRecursive(c, id); if (t != null) { return t; } } return null; }
|