Access Control In DataGrid Header

R

RN1

Consider the following DataGrid:

--------------------------------------------------------------------------------
<asp:DataGrid ID="dgMarks" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" OnCheckedChanged="CheckUncheckAllRows"
AutoPostBack="true" runat="server"/>
</HeaderTemplate>

<ItemTemplate>
<asp:CheckBox ID="chkItem" OnCheckedChanged="CheckChanged"
AutoPostBack="true" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
--------------------------------------------------------------------------------

Note that the CheckBox with the ID chkHeader is in the Header of the
DataGrid. This CheckBox can be accessed in the OnCheckedChanged event
handler of the CheckBox with the ID chkItem with the following code:

--------------------------------------------------------------------------------
Sub CheckChanged(obj As Object, ea As EventArgs)
Dim chkSelHeader As CheckBox

chkSelHeader =
dgMarks.Controls(0).Controls(0).FindControl("chkHeader")
End Sub
--------------------------------------------------------------------------------

If I am not mistaken, because the CheckBox with the ID chkHeader
resides in the Header of the DataGrid, Controls(0) has been used twice
to access this CheckBox.

Can someone please explain me why Controls(0) been used twice to
access the CheckBox that resides in the Header of the DataGrid (whose
ID is chkHeader)? Which controls do the two Controls(0) refer to?

Thanks,

Ron
 
R

RN1

Consider the following DataGrid:

---------------------------------------------------------------------------­-----
<asp:DataGrid ID="dgMarks" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" OnCheckedChanged="CheckUncheckAllRows"
AutoPostBack="true" runat="server"/>
</HeaderTemplate>

<ItemTemplate>
<asp:CheckBox ID="chkItem" OnCheckedChanged="CheckChanged"
AutoPostBack="true" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
---------------------------------------------------------------------------­-----

Note that the CheckBox with the ID chkHeader is in the Header of the
DataGrid. This CheckBox can be accessed in the OnCheckedChanged event
handler of the CheckBox with the ID chkItem with the following code:

---------------------------------------------------------------------------­-----
Sub CheckChanged(obj As Object, ea As EventArgs)
    Dim chkSelHeader As CheckBox

    chkSelHeader =
dgMarks.Controls(0).Controls(0).FindControl("chkHeader")
End Sub
---------------------------------------------------------------------------­-----

If I am not mistaken, because the CheckBox with the ID chkHeader
resides in the Header of the DataGrid, Controls(0) has been used twice
to access this CheckBox.

Can someone please explain me why Controls(0) been used twice to
access the CheckBox that resides in the Header of the DataGrid (whose
ID is chkHeader)? Which controls do the two Controls(0) refer to?

Thanks,

Ron

I don't know why but there are quite a few questions I have put
forward in this ASP.NET newsgroup but don't get any help for them. &
as far as my knowledge in ASP.NET (which is limited I must confess), I
guess the questions I have been asking are pretty basic but still I
don't get any responses for them.

I guess there must be a severe shortage of ASP.NET MVPs, experts &
gurus..... Since long I have been using the various Microsoft
newsgroups like ASP, SQL Server etc. & have always got help from
others but I don't know what's wrong with this newsgroup This
newsgroup has indeed left a bad taste in my mouth.

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top