• GridView中显示bool字段(在数据库中是字符类型)


    法一:

    <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;
                }
            }

    }

  • 相关阅读:
    [题解] LuoguP1587 [NOI2016]循环之美
    [题解] LuoguP3705 [SDOI2017]新生舞会
    [题解] LuoguP3702 [SDOI2017]序列计数
    [题解] LuoguP6476 [NOI Online 2 提高组]涂色游戏
    [题解] LuoguP4240 毒瘤之神的考验
    [题解] LuoguP6156简单题
    [题解] LuoguP6055 [RC-02] GCD
    [题解] LuoguP5050 【模板】多项式多点求值
    AtCoder Grand Contest 028题解
    Codeforces Round #421 (Div. 1) 题解
  • 原文地址:https://www.cnblogs.com/chengpeng/p/2277532.html
Copyright © 2020-2023  润新知