You must Sign In to post a response.
  • Category: ASP.NET

    Grid View Row Color will change according the category wise

    I have grid view , show data on page load. i am import the data from excel in the grid view. then data will import and show in the grid view . then In Excel sheet there is total is coming according the Category. then i want show the Row Color of Grid View Should change when ever data is add category wise.
    Eg: I have 2 categor. Energy and Urban
    Energy have 5 record and urban have 2 record. then energy record will add and show after 5 record which belong to energy.Meand 5 Rows will come in grid view which beong to energy and 6 Row will show the Total of energy. then i want 6 row colour will change.( Means which row show will Total that color will change).

    Thank
  • #725484
    Hi nitin,

    You need to give a separate column for particular cell then you just do that in RowDataBound event of gridview itself using that you can achieve your goal.

    protected void GV_RowDataBound(Object sender,GridviewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
    {
    string controlvalue= (e.Row.FindControl("controlname") as Label).Text;
    if(controlvalue=="condition")
    {
    e.Row.BackColor = System.Drawing.Color.PaleGreen;
    }
    }
    }


    Try something like this ...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #725518
    Hi,

    Row data bound is used to manipulate your gridview row text when bind to gridview for example if you store "Energy" rewrite the row color using below code and change the below code as per your requirement.


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    if (DataBinder.Eval(e.Row.DataItem, "frmdate").ToString() == "Energy") //change condition as per your requirement
    {
    e.Row.BackColor = System.Drawing.Color.Red;
    e.Row.ForeColor = System.Drawing.Color.White;
    }
    }
    }

    Regards
    N.Ravindran
    Your Hard work never fails


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.