GRIDVIEW中有个绑定列 数据库中字段值 为1,2,3等
  
想实现效果为  当为1时,GRIDVIEW中显示 "处理"
              当为2时,GRIDVIEW中显示 "处理中"
谢谢 

解决方案 »

  1.   

    你的datasource是怎么取的
    如果是sql的话,直接case when就可以了
      

  2.   

    同意楼上,或者RowDataBound中处理
      

  3.   

    同意楼上,可以在RowDataBound中处理,也可以将所有数据放到一个dataset里面处理数据后和GRIDVIEW绑定
      

  4.   

    能给出代码吗?
     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    {
            if (GridView1.Rows[e.Row.RowIndex].Cells[5].Text.ToString()=="1")
           
           {
              
           
           }
        }其中的代码不会写
      

  5.   

    给GridView添加RowDataBound消息
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        if(e.Row.Cells[...].Text == "1")
        {
           e.Row.Cells[...].Text  = "处理";
         }
        else if(e.Row.Cells[...].Text == "2")
        {
           e.Row.Cells[...].Text = "处理中";
         }
    }
      

  6.   

    代码应该没问题  if(e.Row.RowType == DataControlRowType.DataRow)
    {
        if(e.Row.Cells[...].Text == "1")
        {
           e.Row.Cells[...].Text  = "处理";
         }
        else if(e.Row.Cells[...].Text == "2")
        {
           e.Row.Cells[...].Text = "处理中";
         }
    }
     可是还是不行  我晕
      

  7.   

    protected void GVRc_RowDataBound(object sender, GridViewRowEventArgs e)
        { 
    if (e.Row.RowType == DataControlRowType.DataRow)
            {
                  if (e.Row.Cells[9].Text.Trim() == "禁用")
                {
                    e.Row.Cells[9].Text = "点击启用";
                }
                else if (e.Row.Cells[9].Text.Trim() == "启用")
                {
                    e.Row.Cells[9].Text = "点击禁用";
                }
            }
    }
      

  8.   

    那就放到dataset里面 
    for(int i=0;i<ds.Table[0].Rows.Count;i++)
    {
        if(ds.Tables[0].Rows[i]["字段"].ToString().Trim()=="1")
        {
            ds.Tables[0].Rows[i]["字段"] = "处理";
        }
    };
    然后在 GRIDVIEW.DataSourse = ds.Tables[0];有小问题自己改下...
      

  9.   

    我晕这个事件没有执行
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Response.Write("fdslkfs");
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[6].Text.Trim() == "处理")
                {
                    e.Row.Cells[6].Text = "gaibain";
                }
                else if (e.Row.Cells[6].Text.Trim() == "处理中")
                {
                    e.Row.Cells[6].Text = "hehe";
                }
            }    }
     Response.Write("fdslkfs");
    这个都没打出来
      

  10.   

    想问下楼主,GridView的数据是不是绑定的?
      

  11.   

    一种方法是  在数据源(dataset或者datatable)中新加入一列,循环一下判断=1 新列的该行插入“处理” =2 插入“处理中”一种方法是 在html里绑定字段时<%#ChangeChineseState(DataBinder.Eval(Container.DataItem,"字段名"))%>
    CS添加方法
    public string ChangeChineseState(object _state)
    {
         if (_state.ToString() == "1")
             return "处理";
         if (_state.ToString() == "2")
             return "处理中";
    }一种方法是 在数据绑定时的事件里判断
    像dingyong7643099() 的做法