法一:
<asp:BoundField DataField="是否启用" HeaderText="是否启用">
<ItemStyle Width="15%" HorizontalAlign="Center" />
</asp:BoundField>
if (ds != null && ds.Tables[0].Rows.Count > 0) // 进行数据绑定前的示意转换
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["是否启用"].ToString() == "1")
ds.Tables[0].Rows[i]["是否启用"] = "是";
else
ds.Tables[0].Rows[i]["是否启用"] = "否";
}
}
法二:
<asp:TemplateField HeaderText="是否启用">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkSFQY" Enabled="false"></asp:CheckBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="15%" />
</asp:TemplateField>
protected void gvMenuList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (((DataRowView)e.Row.DataItem).Row["是否启用"].ToString() == "1")
{
((CheckBox)e.Row.FindControl("chkSFQY")).Checked = true;
}
else
{
((CheckBox)e.Row.FindControl("chkSFQY")).Checked = false;
}
}
}