Template Columns Controls

G

Guest

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?
 
G

Guest

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
 
S

S.M. Altaf [MVP]

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
 
P

Patrick.O.Ige

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
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
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top