我想判断GridView中的第一列的值,如果该值为“数据结构”,就用红色显示。
我的代码是
protected void GV_CourseList_RowDataBound1(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {      
        if (e.Row.Cells[0].Text == "数据结构")
        {
            e.Row.Cells[0].ForeColor=System.Drawing.Color.Red;
        }
        Response.Write(e.Row.Cells[0].Text);//测试一下
    }
}
当数据源是用sqldatasource时就可以正常显示,但用dataset作为数据源时,数据能够在gridview中正常显示,但颜色没有变化。写了一个Response.Write的语句,结果里面的内容都为空,所以颜色判断不出来。
请教个位高手是怎么回事?我就是想用自己的dataset作为数据源,怎么解决?谢谢啦~~~~~~~

解决方案 »

  1.   

    应该不会.检查一下dataset的数据
      

  2.   

    dataset中的数据可以在GridView中正常显示出来,但Response.Write时里面全是空的,很郁闷。
      

  3.   

    if (e.Row.RowIndex >= 0)
            {
                //GridView1.Rows[1].Cells[0].ForeColor = "red";
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    string unitsInStock = DataBinder.Eval(e.Row.DataItem, "type").ToString();
                    if (Convert.ToInt32(unitsInStock) == 1)
                    {
                        e.Row.BackColor = System.Drawing.Color.FromArgb(158, 205, 237);
                    }
                    string unitsInStock1 = DataBinder.Eval(e.Row.DataItem, "lanaguagetype").ToString();
                    if (Convert.ToInt32(unitsInStock1) == 2)
                    {
                        e.Row.BackColor = System.Drawing.Color.FromArgb(170, 205, 240);
                    }
                    string unitsInStock2 = DataBinder.Eval(e.Row.DataItem, "lanatype").ToString();
                    if (Convert.ToInt32(unitsInStock2) == 3)
                    {
                        e.Row.BackColor = System.Drawing.Color.FromArgb(180, 220, 230);
                    }            }
      

  4.   

    谢谢djx520(),用DataBinder.Eval可以搞定。我还是想弄明白为什么e.Row.Cells[0].Text 里面的内容为空。
      

  5.   

    GV_CourseList_RowDataBound1
    不会是调用错了吧  为什么后面会多了个一 如果是自动生成的话 应该是
    GV_CourseList_RowDataBound断点跟进去看看  我去试试试试试试试试试
      

  6.   

    换 e.Row.Cells[1] 呢估计LZ是 DataSet出错
      

  7.   

    e.row.cells[1]也试了,整不成呀。
    dataset 作为数据源可以将数据正常显示在gridview上,我想应该不会错吧。
    xingxing2378(菜猩):你试了吗,可以显示吗?
      

  8.   

    当DataSet被Fill以后,设断点,用放大镜看看DataSet中的数据,看第一列是否为空,或者DataSet是否为空