TemplateColumn with CheckBox DataBind in C#

Q

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
 
E

Elton Wang

You can make any special data binding in
datagrid_ItemDataBound event.

HTH

Elton WAng
(e-mail address removed)
 
Q

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);
}
 

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,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top