如何控制datagrid的显示

breezejfd 2003-12-09 12:44:00
比如我想在datagrid中将符合条件的某几条显示为红色,其它的不变
这个应该怎么写代码?VB
...全文
33 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
XKPZH 2003-12-12
  • 打赏
  • 举报
回复
我有一个大概的例子......看一下....对你有没有用
int i=0;
foreach(DataGridItem dgi in MyDataGrid.Items)
{
if(i%2==0)
{
dgi.BackColor=System.Drawing.Color.Red;

}
i++;

这是使DATAGRID中的偶行有红色显示
XKPZH 2003-12-12
  • 打赏
  • 举报
回复
通过设定datagrid1.SelectedIndex为你所选定的值......
<SelectedItemStyle BackColor="Red"></SelectedItemStyle>
Jouzen 2003-12-12
  • 打赏
  • 举报
回复
在ItemCreate()的时候判断
breezejfd 2003-12-10
  • 打赏
  • 举报
回复
<%# getcolorstr(DataBinder.Eval(Container.DataItem, "filed").ToString()) %>
放在什么地方
acewang 2003-12-09
  • 打赏
  • 举报
回复
参考:
http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp
???2008 2003-12-09
  • 打赏
  • 举报
回复
你在后台加上代码:
我VB的不会写。C#的供参考
public string getcolorstr(string str)
{
if(条件)
{
return "<font color=red>" + str + "</font>";
}
esle
{
return str;
}
}
在前台中<%# getcolorstr(DataBinder.Eval(Container.DataItem, "filed").ToString()) %>
aBoris 2003-12-09
  • 打赏
  • 举报
回复
Function Getcolorstr(ByVal str As String)

if(条件) then

return "<font color=red>" + str + "</font>"

esle

return str
end if
End Function

在前台中<%# getcolorstr(DataBinder.Eval(Container.DataItem, "filed").ToString()) %>
airon2002 2003-12-09
  • 打赏
  • 举报
回复
http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp

up
fxltdwc 2003-12-09
  • 打赏
  • 举报
回复
if((DataGrid1.Items[i].Cells[9].Text=="未审核)
{
DataGrid1.Items[i].BackColor=System.Drawing.Color.LightSkyBlue;
}
flyinglz 2003-12-09
  • 打赏
  • 举报
回复
在itembound事件中可以加一些控制显示的代码,如:

if(条件)
{
e.item.cells...改变颜色
}

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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