我如何...根据状态列更改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.

尝试这样..


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.