Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
for example :
Status Column
============
Active
Active
Active
Unactive - This Status is Unactive Then Unactive Column Color change.




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.
Posted
Updated 20-Jan-14 15:55pm
v2

try like this..

XML
<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>


C#
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";

           }
       }
 
Share this answer
 
v2
Comments
My 5. Perfect. :)
Karthik_Mahalingam 20-Jan-14 22:35pm    
Thanks TD :)
Check my solution. You will smile for sure. :):D
Karthik_Mahalingam 20-Jan-14 22:42pm    
ha ha :)
krishna97 20-Jan-14 22:38pm    
This code not working
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900