我如何...根据状态列更改GRIDVIEW的单元格颜色 [英] How do I...change cell color of GRIDVIEW based on Status Column

查看:86
本文介绍了我如何...根据状态列更改GRIDVIEW的单元格颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for example :
Status Column
============
Active
Active
Active
Unactive - This Status is Unactive Then Unactive Column Color change.









所以我的要求是,如果状态是列是不活动的,则该部分细胞的背景颜色应该在GRIDVIEW中更改为红色。





So my requirement is, if the Status is Column is Unactive, THE background color of that partciular cell should be changed to red color in GRIDVIEW.

推荐答案

尝试这样.. < br $>


try like this..

<asp:GridView id="girdview" runat="server" AutoGenerateColumns="false" OnRowDataBound="girdview_RowDataBound">
            <Columns>
                <asp:BoundField DataField="Status" HeaderText="Status" />
                <asp:BoundField DataField="others" HeaderText="others" />
            </Columns>

        </asp:GridView>







protected void girdview_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           int statuscolumnIndex = 0; // check in your gridview
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               string status = DataBinder.Eval(e.Row.DataItem, "Status").ToString();
               if (status == "Unactive")
                   e.Row.Cells[statuscolumnIndex].Style["background-color"] = "Red";

           }
       }


你的意思是这些?



http://msdn.microsoft .com / zh-cn / library / system.windows.forms.datagridviewcell.style(v = vs.110).aspx [ ^ ]



http:// msdn .microsoft.com / zh-cn / library / system.windows.forms.datagridviewcellstyle(v = vs.110).aspx [ ^ ]
You mean these?

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.style(v=vs.110).aspx[^]

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle(v=vs.110).aspx[^]


Just提醒你没有 Unactive 这样的词,而不是无效



对于您的问题,您可以关注Karthik的解决方案。
Just to alert you that there is no such word like "Unactive", rather it is "Inactive".

For your issue, you can follow Karthik's Solution.


这篇关于我如何...根据状态列更改GRIDVIEW的单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆