TemplateColumn with CheckBox DataBind in C#

Discussion in 'ASP .Net Datagrid Control' started by Qemajl, Feb 26, 2005.

  1. Qemajl

    Qemajl Guest

    Hi!

    I'm having problem binding a checkbox to data from a DataSet.

    I've seen solutions like <%#DataBinder.Eval(Container.DataItem,
    "ColumnToBind")%> but this code must be added in aspx file and I'm
    generating the datagrid from code behind.

    How can i bind data from a dataset to a templatecolumn with ckeckbox
    in code behind? I'm using C#

    /thanks
     
    Qemajl, Feb 26, 2005
    #1
    1. Advertising

  2. Qemajl

    Elton Wang Guest

    You can make any special data binding in
    datagrid_ItemDataBound event.

    HTH

    Elton WAng


    >-----Original Message-----
    >Hi!
    >
    >I'm having problem binding a checkbox to data from a

    DataSet.
    >
    >I've seen solutions like <%#DataBinder.Eval

    (Container.DataItem,
    >"ColumnToBind")%> but this code must be added in aspx

    file and I'm
    >generating the datagrid from code behind.
    >
    >How can i bind data from a dataset to a templatecolumn

    with ckeckbox
    >in code behind? I'm using C#
    >
    >/thanks
    >.
    >
     
    Elton Wang, Feb 27, 2005
    #2
    1. Advertising

  3. Qemajl

    Qemajl Guest

    thx... solved the problem with following code in ItemDataBound event.help...

    protected override void OnItemDataBound(DataGridItemEventArgs e)
    {
    try
    {
    string myStr;

    if((e.Item.ItemType != ListItemType.Header) &
    (e.Item.ItemType != ListItemType.Footer))
    {
    myStr = Convert.ToString(DataBinder.Eval(e.Item.DataItem,"RegisterVisit"));

    if (myStr == String.Empty)
    ((CheckBox)e.Item.Cells[4].Controls[0]).Visible = false;
    else
    {
    ((CheckBox)e.Item.Cells[4].Controls[0]).Checked = Convert.ToBoolean(myStr);
    }
    }
    }
    catch(Exception E)
    {
    }

    base.OnItemDataBound (e);
    }
    "Elton Wang" <> wrote in message news:<1e8a01c51cfa$5b413910$>...
    > You can make any special data binding in
    > datagrid_ItemDataBound event.
    >
    > HTH
    >
    > Elton WAng
    >
    >
    > >-----Original Message-----
    > >Hi!
    > >
    > >I'm having problem binding a checkbox to data from a

    > DataSet.
    > >
    > >I've seen solutions like <%#DataBinder.Eval

    > (Container.DataItem,
    > >"ColumnToBind")%> but this code must be added in aspx

    > file and I'm
    > >generating the datagrid from code behind.
    > >
    > >How can i bind data from a dataset to a templatecolumn

    > with ckeckbox
    > >in code behind? I'm using C#
    > >
    > >/thanks
    > >.
    > >
     
    Qemajl, Feb 28, 2005
    #3
    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. Nus Pieds

    TemplateColumn CheckBox

    Nus Pieds, Jul 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    391
    Nus Pieds
    Jul 16, 2003
  2. ReskatoR
    Replies:
    0
    Views:
    319
    ReskatoR
    Oct 8, 2008
  3. Michael
    Replies:
    0
    Views:
    238
    Michael
    Dec 29, 2003
  4. Paul

    TemplateColumn to display Checkbox in DataGrid

    Paul, Apr 20, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    157
    Scott Mitchell [MVP]
    Apr 21, 2004
  5. JasmineC

    Help with CheckBox inside a TemplateColumn

    JasmineC, Sep 2, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    127
    Eliyahu Goldin
    Sep 2, 2004
Loading...

Share This Page