I have a Database Table called Student.Its Fields are :
我有一个名为Student的数据库表。它的字段:
Name Varchar(20),
IsActive Int(1). // 1 for checked. 0 For unchecked.
I am adding this table into grid.
我正在将这个表添加到网格中。
What I want to do is, All the related checkboxes of Gridview row should be checked, If database record have IsActive = 1 value, else Unchecked.
我要做的是,检查Gridview行的所有相关复选框,如果数据库记录为IsActive = 1,则不检查else。
1 个解决方案
#1
2
You can bind it like this in the gridview:-
您可以在gridview中这样绑定它:-
<asp:GridView ID="grdStudents" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkIsActive" runat="server" Checked='<%# Eval("IsActive").ToString() == "1" ? true : false %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
#1
2
You can bind it like this in the gridview:-
您可以在gridview中这样绑定它:-
<asp:GridView ID="grdStudents" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkIsActive" runat="server" Checked='<%# Eval("IsActive").ToString() == "1" ? true : false %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>