It should have worked. Make sure you databind the datagrid before you
attempt looping through its items and also add a condition to examine the
datagrid itemtype first, e.g.
foreach (DataGridItem item in dgAddresses)
{
switch (item.ItemType )
{
case ListItemType.Header:
// find the chbAll control
break;
case ListItemType.Item:
//find the individual controls
break;
}
}
I have a sample where I used the event handler of the checkbox to process
whatever action needed instead of looping through the entire datagrid:
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx

Signature
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
> I have datagrid , i edited the template column by adding checkbox on in
> templateheader and one in templateitem
[quoted text clipped - 14 lines]
>
> how can i get access to them?
S.M. Altaf [MVP] - 29 Oct 2005 16:47 GMT
Hi,
You may also want to change this:
CheckBox chk = item.FindControl("chbAll") as CheckBox;
to:
CheckBox chk = (CheckBox)item.FindControl("chbAll");
I can't say I've ever heard of "as" in C#.
HTH,
Altaf
--------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com
It should have worked. Make sure you databind the datagrid before you
attempt looping through its items and also add a condition to examine the
datagrid itemtype first, e.g.
foreach (DataGridItem item in dgAddresses)
{
switch (item.ItemType )
{
case ListItemType.Header:
// find the chbAll control
break;
case ListItemType.Item:
//find the individual controls
break;
}
}
I have a sample where I used the event handler of the checkbox to process
whatever action needed instead of looping through the entire datagrid:
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Raed Sawalha" wrote:
> I have datagrid , i edited the template column by adding checkbox on in
> templateheader and one in templateitem
>
> the problem i have i can not get access to the checkbox at runtime , i did
> this to get them but not worked:
>
> string ClientID = "";
> foreach(DataGridItem item in dgAddresses.Items)
> {
>
> CheckBox chk = item.FindControl("chbAll") as CheckBox;
> if(chk != null)
> ClientID = chk.ID;
> else continue;
>
> }
>
> how can i get access to them?
Patrick.O.Ige - 30 Oct 2005 02:47 GMT
Yeah Altaf
Hi,
You may also want to change this:
CheckBox chk = item.FindControl("chbAll") as CheckBox;
to:
CheckBox chk = (CheckBox)item.FindControl("chbAll");
I can't say I've ever heard of "as" in C#.
HTH,
Altaf
------------------------------------------------------------------------------
All that glitters has a high refractive index.
www.mendhak.com
"Phillip Williams" <Phillip.Williams@webswapp.com> wrote in message news:77944E0C-2A68-43FE-B1A6-0A192909F603@microsoft.com...
It should have worked. Make sure you databind the datagrid before you
attempt looping through its items and also add a condition to examine the
datagrid itemtype first, e.g.
foreach (DataGridItem item in dgAddresses)
{
switch (item.ItemType )
{
case ListItemType.Header:
// find the chbAll control
break;
case ListItemType.Item:
//find the individual controls
break;
}
}
I have a sample where I used the event handler of the checkbox to process
whatever action needed instead of looping through the entire datagrid:
http://www.societopia.net/Samples/DataGrid_ChildControlsEvents.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Raed Sawalha" wrote:
> I have datagrid , i edited the template column by adding checkbox on in
> templateheader and one in templateitem
>
> the problem i have i can not get access to the checkbox at runtime , i did
> this to get them but not worked:
>
> string ClientID = "";
> foreach(DataGridItem item in dgAddresses.Items)
> {
>
> CheckBox chk = item.FindControl("chbAll") as CheckBox;
> if(chk != null)
> ClientID = chk.ID;
> else continue;
>
> }
>
> how can i get access to them?