关于datagridview的问题

jason110163 2009-12-27 05:54:10
请帮忙修改成如图效果

图片:

如果图片显示不了,直接访问
http://hi.baidu.com/qq881616/album/item/e37e38465b9765396a63e50b.html

当number值为1、2、4、5、7 column1列中 显示字母A 红色背景
当number值为0、3、6、8、9 column1列中 显示字母B 蓝色背景

源文件我上传到网盘中了
下载地址: http://www.rayfile.com/files/4e865a38-f2c0-11de-8bd6-0014221b798a/

请修改好后 发送到我邮箱 110163@qq.com

...全文
103 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianliang1 2009-12-27
  • 打赏
  • 举报
回复
搞那么链接?
你把你的代码粘出来大家才好帮你。。。
jason110163 2009-12-27
  • 打赏
  • 举报
回复
问题解决了 ,原来是循环时候 最后碰到空值也强行转换int导致的错误
jason110163 2009-12-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jason110163 的回复:]
引用 6 楼 zhou_zy 的回复:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                int x = (int)dataGridView1.Rows[i].Cells["number"].Value;
                //1、2、4、5、7
                if (x == 1 || x == 2 || x == 4 || x == 5 || x == 7)
                {
                    dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Red;
                }
                else
                {
                    dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Blue;
                }
            }


我还是没搞定呀。。
哪个高手能直接联系我QQ:110163 帮我搞定下这个小问题
[/Quote]
会提示
未处理 System.NullReferenceException
要怎么解决?
悔说话的哑巴 2009-12-27
  • 打赏
  • 举报
回复
你的QQ号码很牛哦
jason110163 2009-12-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhou_zy 的回复:]
for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                int x = (int)dataGridView1.Rows[i].Cells["number"].Value;
                //1、2、4、5、7
                if (x == 1 || x == 2 || x == 4 || x == 5 || x == 7)
                {
                    dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Red;
                }
                else
                {
                    dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Blue;
                }
            }
[/Quote]

我还是没搞定呀。。
哪个高手能直接联系我QQ:110163 帮我搞定下这个小问题
zhou_zy 2009-12-27
  • 打赏
  • 举报
回复
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
int x = (int)dataGridView1.Rows[i].Cells["number"].Value;
//1、2、4、5、7
if (x == 1 || x == 2 || x == 4 || x == 5 || x == 7)
{
dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Red;
}
else
{
dataGridView1.Rows[i].Cells["Columns1"].Style.BackColor = Color.Blue;
}
}
zzxap 2009-12-27
  • 打赏
  • 举报
回复
将tr改成str 手漏
silentwins 2009-12-27
  • 打赏
  • 举报
回复
在OnRowDataBound事件里面,取得number的值,再取得column1的控件,再显示
试试吧,很好玩的~~


if((Label)e.Item.Cell[2].Text=="1") //Cell2指第三列,单元格里没控件的话用Cells
(Label)e.Item.FindControl("LabelID").BackColor = "Red"; //单元格里有控件用FindControl()
else
(Label)e.Item.FindControl("LabelID").BackColor = "Red";
jason110163 2009-12-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zzxap 的回复:]
前台
<%# setString(eval("列名").Tostring())%>
后台
public void  setString(str)
{
string strReturn="";
if(str=1||tr=2||tr=3||tr=4||tr=5||tr=7)
{
  strRretu= <font color=red>" + str + " </font>"
}
if(str=0||tr=3||tr=6||tr=8||tr=9)
{
  strRretu= <font color=blue>" + str + " </font>"
}
return strRretu;
}

[/Quote]

不好意思呀,自己试着改了下没成功
能不能改好发到我邮箱
源文件下载地址: http://www.rayfile.com/files/4e865a38-f2c0-11de-8bd6-0014221b798a/
zzxap 2009-12-27
  • 打赏
  • 举报
回复
请修改好后 发送到我邮箱 110163@qq.com

zzxap 2009-12-27
  • 打赏
  • 举报
回复
前台
<%# setString(eval("列名").Tostring())%>
后台
public void setString(str)
{
string strReturn="";
if(str=1||tr=2||tr=3||tr=4||tr=5||tr=7)
{
strRretu=<font color=red>" + str + "</font>"
}
if(str=0||tr=3||tr=6||tr=8||tr=9)
{
strRretu=<font color=blue>" + str + "</font>"
}
return strRretu;
}

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧