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

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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>
 
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
 
Back
Top