小弟在存如数据的时候用True来代表男,Flase来代表女,但是提取数据后填充到DataGrid里面也是显示的True和Flase,我用到了储存过程,怎么判断True为男,Flase为女呀?
可以写到储存过程中判断返回吗?如何做?

解决方案 »

  1.   

    <%# DataBinder.Eval(Container.DataItem,"sex").ToString()=="True"?"男":"女" %>
      

  2.   

    你可以在itemdatabound里面来进行判断和重写值
      

  3.   

    protected void FormatDataGrid_ItemDataBound(object source, 
    System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
          //  确保处理的是数据行,而不是Header或者Footer
          if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
          {
            //  得到True/False字段的值
            string isTrue= (string)DataBinder.Eval(e.Item.DataItem, "字段");        if (isTrue== "true")
            {
              // '  设定文字和背景颜色
            e.Item.Cells[2].Text = "男"
            e.Item.Cells[2].Style.Add("font-weight", "bold")
            e.Item.Cells[2].ForeColor = System.Drawing.Color.Red
            e.Item.BackColor = System.Drawing.Color.AliceBlue
            }
            else
            {
              e.Item.Cells[2].Text = "女";
            }
          }
      

  4.   

    Protected Sub FormatDataGrid_ItemDataBound(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) 
     If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then 
       Dim isTrue As String = CType(DataBinder.Eval(e.Item.DataItem, "字段"), String) 
       If isTrue = "true" Then 
         e.Item.Cells(2).Text = "男" 
         e.Item.Cells(2).Style.Add("font-weight", "bold") 
         e.Item.Cells(2).ForeColor = System.Drawing.Color.Red 
         e.Item.BackColor = System.Drawing.Color.AliceBlue 
       Else 
         e.Item.Cells(2).Text = "女" 
       End If 
     End If 
    End Sub
      

  5.   

    首先你把要显示性别的那个列做成模版列.然后在模版列中加入一个label.设置label的属性
    value='<%# GetSex(DataBinder.Eval(Container.DataItem,"sex") )%>' 
    在cs文件中写一个函数如下:
    protected string GetSex (string strSEX)
    {
       if(strSEX)
          return "男";
      else
        return "女";
    }
    存储过程中不用做任何判断.只要把数据原样取出来就行.
      

  6.   

    DataBinder.Eval(Container.DataItem,"sex") 加上.tostring();
      

  7.   

    谢谢各位,现在能够解决问题了。
    但是我还是想知道:
    <%# DataBinder.Eval(Container.DataItem,"sex").ToString()=="True"?"男":"女" %>
    这样的方法VB有办法表达吗?
      

  8.   

    谢谢各位,现在能够解决问题了。
    但是我还是想知道:
    <%# DataBinder.Eval(Container.DataItem,"sex").ToString()=="True"?"男":"女" %>
    这样的方法VB有办法表达吗?
    -------------------------------------------------------------------------------------
    <%# Microsoft.VisualBasic.IIf(DataBinder.Eval(Container.DataItem, "sex").ToString = "True","男","女") %>