Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i have grid view in that for one row and 3 columns. first two is as it is and 3rd column having column-span based on result set

ex
ID category sub category
1 sales jan
Feb
march

2 production Jan
Feb

3 release jan



so i am using below code for alternative color but sub category wise alternative color comming .
i need alternative color base on ID and category not sub category.

Can you provide solution for this.

C#
AlternatingRowStyle-CssClass="alt"
and
CSS
.Grid .alt
      {
         
          background:#DEEDF5;
      }
Posted

1 solution

Try
GridView.RowDatabound event

http://msdn.microsoft.com/en-us/library/aa479342.aspx

GridView.RowCreated event

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcreated%28v=vs.110%29.aspx



C#
void productsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {     
   int ID= Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"ID"));
   string strCategory= Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"Category"));

     if (ID== 1 && strCategory == "sales")            
            e.Row.BackColor = Color.Yellow;
     else if(ID== 2 && strCategory == "production")
            e.Row.BackColor = Color.Gray;
    }
}
 
Share this answer
 
v3
Comments
kanna443 17-Jul-14 6:03am    
i am generating row span of row databound event.data comming properly but problem with alternative color.
pradiprenushe 17-Jul-14 6:21am    
int ID = 0;
rowdatabound()
{
int idtemp = find id from gridrow;
id not equal idtemp
{
id = idttemp;
change color
}


}

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