首页 新闻 会员 周边

gridview的一个问题

0
悬赏园豆:5 [已解决问题] 解决于 2010-09-19 15:02

代码
1 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowType == DataControlRowType.DataRow)
4 {
5 //string title = (string)(DataBinder.Eval(e.Row.DataItem,"cls"));不知道为什么不行
6   string ti = e.Row.Cells[3].Text.ToString();
7 if ( ti == "二班")
8 {
9 e.Row.BackColor = System.Drawing.Color.Red;
10 }
11 }
12 }

 

为什么行不变颜色?

时间都去哪了的主页 时间都去哪了 | 初学一级 | 园豆:51
提问于:2010-09-14 16:20
< >
分享
最佳答案
0

解决方案:主要是绑定后过滤
 GridView1.DataBind();
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            DataRowView mydrv = myds.Tables["0"].DefaultView[i];
            string score = Convert.ToString(mydrv["score"]);
            if (Convert.ToDouble(score) < 34297.00)//大家这里根据具体情况设置可能ToInt32等等
            {
                GridView1.Rows[i].Cells[4].BackColor = System.Drawing.Color.Red;
            }
        }

收获园豆:5
Astar | 高人七级 |园豆:40805 | 2010-09-14 23:26
其他回答(4)
0

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='';");

}

//单击行改变行背景颜色

if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Attributes.Add(
"onclick", "this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");

}
这是一个例子!请参考!

FlyDragon | 园豆:396 (菜鸟二级) | 2010-09-14 16:31
0

是否与前台的css样式有冲突?

nabber | 园豆:479 (菜鸟二级) | 2010-09-14 16:41
0

他的代码有问题!

Ms'h | 园豆:220 (菜鸟二级) | 2010-09-14 18:06
0
 7      if ( ti == "二班")
8 {
9 e.Row.BackColor = System.Drawing.Color.Red;
10 }

问题解析:在第"8"打断点跟踪,看是否程序能进去,如果进不去就是第“6”行的代码有问题或者是
对应的单元格没有"二班"的数据。
sms | 园豆:215 (菜鸟二级) | 2010-09-15 12:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册