Home All Groups Group Topic Archive Search About

TemplateColumn with CheckBox DataBind in C#

Author
26 Feb 2005 3:38 PM
Qemajl
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

Author
27 Feb 2005 6:30 PM
Elton Wang
You can make any special data binding in
datagrid_ItemDataBound event.

HTH

Elton WAng
elton_w***@hotmail.com

>-----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
Show quoteHide quote
>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
>.
>
Author
28 Feb 2005 1:46 PM
Qemajl
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);
}
Show quoteHide quote
"Elton Wang" <anonym***@discussions.microsoft.com> wrote in message news:<1e8a01c51cfa$5b413910$a401280a@phx.gbl>...
> You can make any special data binding in
> datagrid_ItemDataBound event.
>
> HTH
>
> Elton WAng
> elton_w***@hotmail.com
>
> >-----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
> >.
> >