Checkbox binding in datagrid?

G

Guest

Hi,

How do you set the checked property for checkbox column in a datagrid? The
SimpleYn is a bit column value in the database. When I try it, I'm getting a
cast error. Thanks.

<asp:TemplateColumn HeaderText="Sample">
<ItemTemplate>
<asp:CheckBox ID="Sample"
Checked='<%# DataBinder.Eval(Container.DataItem, "SampleYn")%>'
runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
 
S

Sebastian Wojciechowski

call a function there
try this
<asp:CheckBox ID="Sample" Checked='<%#
ToBool(DataBinder.Eval(Container.DataItem, "SampleYn")) %>' runat="server"
/>

and create function ToBool that will convert the bit value to bool. Or try
to onvert it inline Cnvert.ToBool(DataBinder.Eval(Container.DataItem,
"SampleYn")).

Hope this helps.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top