how to check/Uncheck a checkbox dynamically in a datagrid in asp.n

G

Guest

Hi

I have datagrid with 8 items. Out of which 2 items are checkboxes. Data is
binded dynamically to the datagrid

Based on some values from the database I have to check or uncheck the
checkbox in the datatgrid.

Does any one know how to do this?

Thx
Sileesh
 
K

Ken Cox [Microsoft MVP]

You can use an IIF statement in the ItemTemplate like this when you get the
value from the database:

Checked='<%# IIF(DataBinder.Eval(Container,
"DataItem.Boolean"),"true","false") %>'

Or, if the database already has a boolean, you ca do this:

Checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>'

More code below.

Does this help?

Ken
Microsoft MVP [ASP.NET]



<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:CheckBox id=match runat="server" onCheckedChanged="updateStatus"
Checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>'
AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:CheckBox id="Checkbox1" runat="server"
onCheckedChanged="updateStatus" Checked='<%# IIF(DataBinder.Eval(Container,
"DataItem.Boolean"),"true","false") %>' AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
 
G

Guest

Ken

Thanks for the exanple. Thanks for ur effort os explaining.
but I am working on windows form. In that i don't runat server procedures.
Can u tell how i can do with code behind in vb.net.

Rekha

Ken Cox said:
You can use an IIF statement in the ItemTemplate like this when you get the
value from the database:

Checked='<%# IIF(DataBinder.Eval(Container,
"DataItem.Boolean"),"true","false") %>'

Or, if the database already has a boolean, you ca do this:

Checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>'

More code below.

Does this help?

Ken
Microsoft MVP [ASP.NET]



<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:CheckBox id=match runat="server" onCheckedChanged="updateStatus"
Checked='<%# DataBinder.Eval(Container, "DataItem.Boolean") %>'
AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Boolean Value">
<ItemTemplate>
<asp:CheckBox id="Checkbox1" runat="server"
onCheckedChanged="updateStatus" Checked='<%# IIF(DataBinder.Eval(Container,
"DataItem.Boolean"),"true","false") %>' AutoPostBack="True">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

Sileesh said:
Hi

I have datagrid with 8 items. Out of which 2 items are checkboxes. Data is
binded dynamically to the datagrid

Based on some values from the database I have to check or uncheck the
checkbox in the datatgrid.

Does any one know how to do this?

Thx
Sileesh
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top