例如我在数据库里将性别字段的值保存为1,0
但是要在输出时输出男,女,并和Gatagrid绑定.请问需要怎么做啊?谢谢

解决方案 »

  1.   

    在RowDataBound
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (e.Row.Cells[2].Text.Trim() == "1")
                    {
                        e.Row.Cells[2].Text = "男";
                    }
                    else if (e.Row.Cells[2].Text.Trim() == "0")
                    {
                        e.Row.Cells[2].Text = "女";
                    }
                 }
             }
      

  2.   

    添加模版列,插入dropdownlist,可以通过判断用代码绑定,也可以直接在设计的时候将将数据绑定到dropdownlist
      

  3.   

    对性别使用模版列
    <asp:TemplateField>
         <ItemTemplate>
             <asp:Label ID="Sex" runat="server" Text='<%#Eval("BookId").ToString()=="1"?"男":"女"%>' />
         </ItemTemplate>
    </asp:TemplateField>