如果条件为真,如何更改gridview的行颜色? [英] how to change row color of gridview if condition is true ?
本文介绍了如果条件为真,如何更改gridview的行颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,其中一些列作为名称类状态..
在网格视图中从表中获取值..
i如果状态是no then row color = red else yellow ..
解决方案
如果你从数据库查询中获取数据,那么你应该编写像'select columns,case at status ='之类的查询在'then'R'其他'Y'结束为来自tbl'的cl ..然后绑定网格..
然后在gridview写项目模板中这样:
< asp:GridView runat = 服务器 ID = grd >
< 列 >
< asp:TemplateField HeaderText = Header1 >
< ItemTemplate > ;
< asp:标签 runat = server ID = lbl CssClass =' <% #Eval( cl )%> ' 宽度 = 100% 文本 =' <% #Eval( ID)%> ' > < / asp:标签 >
< ; / ItemTemplate >
< / asp:TemplateField >
< / Columns >
< / asp:GridView >
然后写样式表如下:
< style type = text / css >
.R
{
background-color:Red;
}
.Y
{
background-color:Black;
}
< / style > 跨度>
i have a table with some columns as name class status..
in grid view in am fetching the values from the table..
i want if the status is no then row color = red else yellow..
解决方案
if u get the data from database query then u should write query like 'select columns,case when status='on' then 'R' else 'Y' end as cl from tbl'.. then bind the grid..
then in gridview write item template like this:
<asp:GridView runat="server" ID="grd"> <Columns> <asp:TemplateField HeaderText="Header1"> <ItemTemplate> <asp:Label runat="server" ID="lbl" CssClass='<%#Eval("cl") %>' Width="100%" Text='<%#Eval("ID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Then Write Style Sheet like This:
<style type="text/css"> .R { background-color: Red; } .Y { background-color: Black; } </style>
这篇关于如果条件为真,如何更改gridview的行颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文