怎么把数据库中的信息,读出梆定到GRIDVIEW里边的时候,把0,1,转成是否啊
不需要用RADIOBUTTON,最好是和否字能用不同的颜色表示

解决方案 »

  1.   

    可以在拼SQL 的时候 case when 一下 。
      

  2.   

    在sql语句里面可以控制
           stuSex= case  stuSex when '0' then '男' else '女' end ,
      

  3.   

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

  4.   

    在后台写个方法
    protected String ReplaceString(object o)
    {
     if(o == null || Convert.ToString(o) == String.Empty)
     {
       return String.Empty;
     } if(Convert.ToInt32(o) == 1)
     {
       return "<font color='red'>是</font>";
     }
     else
     {
       return "<font color='blue'>否</font>";
     }
    }
    在前台调用<%# ReplaceString(Eval("type"))%>
      

  5.   

    用函数也可以
    <%# publicPrograms.GetSex(Eval("sex").ToString())%>后台
    public static string GetSex(string sex)
        {
            
            if (sex == "1")
            {
                return "是";
                }
                else
                {
                    return "否";
                }
            }
        }
      

  6.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {        if (e.Row.RowType == DataControlRowType.DataRow)
            {            
                Label lblSex = (Label)e.Row.Cells[0].Controls[1];
                if (lblSex == "0")
                    lblSex.Text = "男";
                else
                    lblSex.Text = "女";  
            }
        }
    这个比较好,还可以自己设颜色 lblSex.ForeColor=Color.Red