how to bind data to checkbox in datagrid

L

LiFo

hi
i have a datagrid and one colume is a bool
if i use a normal asp:BoundColumn is shows as true or false
and i want it to show as a checkbox
but if i use a asp:TemplateColumn as this
<asp:TemplateColumn>
<HeaderTemplate>
<b>Aktiv</b>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox Runat="server" ID="checkbox" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

i only get a checkbox how do i bind the data to the checkbox
and i also want it to only bee able to check the box when it is in edit mode
 
J

Jos

LiFo said:
hi
i have a datagrid and one colume is a bool
if i use a normal asp:BoundColumn is shows as true or false
and i want it to show as a checkbox
but if i use a asp:TemplateColumn as this
<asp:TemplateColumn>
<HeaderTemplate>
<b>Aktiv</b>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox Runat="server" ID="checkbox" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

i only get a checkbox how do i bind the data to the checkbox
and i also want it to only bee able to check the box when it is in
edit mode

For Visual Basic:
<asp:CheckBox Runat="server" ID="checkbox1"
Checked='<%# DataBinder.Eval(Container.DataItem, "myField") %>' >
</asp:CheckBox>

I suggest using "Checkbox1" and not "Checkbox" for the ID, as Checkbox
can cause confusion between the type and the instance.
 
L

LiFo

i am using c# and cant get it to work ???



Jos said:
For Visual Basic:
<asp:CheckBox Runat="server" ID="checkbox1"
Checked='<%# DataBinder.Eval(Container.DataItem, "myField") %>' >
</asp:CheckBox>

I suggest using "Checkbox1" and not "Checkbox" for the ID, as Checkbox
can cause confusion between the type and the instance.
 
J

Jos

LiFo said:
i am using c# and cant get it to work ???

I checked and it's exactly the same in c#.
Did you replace "myField" with the actual name of your field,
for instance "Activ"?

What is your error message?
 

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