Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Template Columns Controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Raed Sawalha - 29 Oct 2005 09:53 GMT
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?
Phillip Williams - 29 Oct 2005 11:55 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.