有什好的办法,根据数据设置gridview行背景色??

解决方案 »

  1.   

    比如:待批的backcolor无色,批准的绿色,重新申报的黄色,不批的红色所以有没有好的办法可以根据绑定Gridview的数据设置谁有类似这样问题,好的解决方法的代码可以让我参考下···
      

  2.   

    protected void CourseGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
            if(e.Row.cells[].text.equals(""))//判断数据
                    {
               e.Row.BackColor = Color.Red;
                    
              
      

  3.   

    LS的可行,
    LZ真有意思,昵称叫Eleven ,问题点数 11
    11 是你的幸运号码啊!
      

  4.   

    我是想获取gridview中模板列的值,怎么获取,如下:
                        <asp:TemplateField HeaderText="审批结果">
                            <ItemTemplate>
                                <%#ShenPiJieGuo(Eval("审批结果").ToString().Trim())%>
                            </ItemTemplate>
                        </asp:TemplateField>
      

  5.   

    ItemTemplate  里面的话 在原2楼的基础上  使用findcontrol就行
      

  6.   

    这类问题通过GridView的RowDataBound处理是一种标准做法。
    我也agree二楼。不过我本人不太喜欢从控件里把数据“扣”出的那种感觉。protected void CourseGridView_RowDataBound(object sender, GridViewRowEventArgs e) 

      if (e.Row.RowType == DataControlRowType.DataRow) 
      { 
        System.Data.DataRowView drv = e.Row.DataItem as DataRowView;
        string result = drv["审批结果"].ToString();
        if(result == "批准")
            e.Row.BackColor=System.Drawing.Color.Green;
        else if(result == "重新申报")
            e.Row.BackColor=System.Drawing.Color.Yellow;
        else if(result == "不批")
           e.Row.BackColor=System.Drawing.Color.Red;  
      }
    }
      

  7.   


     if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");
                //当鼠标离开的时候 将背景颜色还原的以前的颜色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            }
      

  8.   

    switch(result)
            {
                case "批": 
                    row.BackColor = Color.FromKnownColor(KnownColor.LightYellow);
                    break;
                case "未批"://主体
                    row.BackColor = Color.FromKnownColor(KnownColor.LightSeaGreen);
                    break;
                default:
                    break;
            }
      

  9.   

    去 asp.net屋看看吧,有源码.