Template Columns Controls

Discussion in 'ASP .Net' started by =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Oct 29, 2005.

  1. 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?
     
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Oct 29, 2005
    #1
    1. Advertising

  2. 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?
     
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Oct 29, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message news:...
    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?
     
    S.M. Altaf [MVP], Oct 29, 2005
    #3
  4. Yeah Altaf
    "S.M. Altaf [MVP]" <> wrote in message news:...

    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" <> wrote in message news:...
    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, Oct 30, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. helpful sql
    Replies:
    0
    Views:
    845
    helpful sql
    May 19, 2005
  2. Tudor
    Replies:
    1
    Views:
    137
    Teemu Keiski
    Jul 15, 2003
  3. daniel kurtz

    Capture events on controls in template columns

    daniel kurtz, Oct 10, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    114
    Eliyahu Goldin
    Oct 11, 2005
  4. Tudor
    Replies:
    1
    Views:
    141
    Teemu Keiski
    Jul 15, 2003
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    922
    Vinki
    Apr 25, 2007
Loading...

Share This Page