https://www.cnblogs.com/zxd543/p/3121169.html
效果如下(以会员价为例)
会员价(MemberPrice)字段的数据库类型为int(1表示true,0表示false)
页面绑定如下:
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
![复制代码](https://common.cnblogs.com/images/copycode.gif)
<asp:TemplateField HeaderText="会员价"> <ItemStyle HorizontalAlign="Center" Width="60px" /> <ItemTemplate> <asp:CheckBox ID="cbMemberPrice1" runat="server" Checked='<%# Convert.ToBoolean(Eval("MemberPrice")) %>' /> </ItemTemplate> </asp:TemplateField>
![复制代码](https://common.cnblogs.com/images/copycode.gif)
绑定也可换成:Checked = ‘<%#(Eval("MemberPrice", "{0}") == "1") ? true:false%>’或
Checked = ‘<%#Eval("MemberPrice").ToString()=="1"?true:false%>‘
MemberPrice数据库字段
也可以在后台绑定(推荐)
页面需要绑定,不加判断。操作麻烦,但是便于更改和维护GridView的RowDataBound事件
e.Row.RowType == DataControlRowType.DataRow //判断是否为数据行否则读取标题行会报错
![复制代码](https://common.cnblogs.com/images/copycode.gif)
Text='<%# Eval("MemberPrice")%>' /> protected void gvShow_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBox cbMemberPrice1 = (CheckBox)e.Row.FindControl("cbMemberPrice1"); cbMemberPrice1.Checked = cbMemberPrice1.Text == "1" ? true : false; cbMemberPrice1.Text = string.Empty; } }
![复制代码](https://common.cnblogs.com/images/copycode.gif)
完成效果开头图像所示:成功捆绑CheckBox状态
标签:GridView,Checked,cbMemberPrice1,绑定,CheckBox,选中,Row From: https://www.cnblogs.com/Dongmy/p/17362747.html