Click here to Skip to main content
15,885,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using GridView templates for displaying data, Here i have two columns actual, estimate costs. If there actual cost cross the estimate cost(actual cost grater then estimated), I have to change that row color dynamically in GridView.
Posted
Updated 21-Dec-10 1:51am
v2
Comments
TweakBird 21-Dec-10 7:51am    
Corrected spells & capitalization.

hi try it
protected void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      Textbox tbx1 = (TextBox)e.Row.FindControl("ActualCostTextbox");
      Textbox tbx2 = (TextBox)e.Row.FindControl("EstimatedCostTextbox");
      if (tbx1 != null&&tbx2 != null)
      {
         // Your code.....
      }
    }
  }
 
Share this answer
 
Comments
fjdiewornncalwe 21-Dec-10 9:20am    
Hey There. Please read the answers already given and if your answer is the same, just note that with a vote or a comment on that answer. As you are new here, I won't downvote you for posting the same answer that Sandeep gave above. Cheers. (Good answer, BTW)
For Datagrid the event is 'ItemDataBound' and for Gridview the event is 'RowDataBound'.

sample:
C#
protected void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
     Textbox tbx1 = (TextBox)e.Row.FindControl("ActualCostTextbox");
     Textbox tbx2 = (TextBox)e.Row.FindControl("EstimatedCostTextbox");
     if (tbx1 != null & tbx2 != null)
     { 
         // compare, validate the values of tbx1 & tbx2
         // you got tbx1.Text & tbx2.Text value here. 
         // Do any calculation desired.
         // based on it logic, set the CSS of the row.
     }
}
 
Share this answer
 
Comments
srinivasvempa 21-Dec-10 5:58am    
tanx but i am not using any controls in girdview i am binding data with itemtemplate evil
Sandeep Mewara 21-Dec-10 6:08am    
Itemtemplate itself does not show anything! There must/has to be some control in it. Right?
Handle RowDataBound event of the GridView and apply your logic over there.

RowDataBound event will fire at every row which is created while DataBound
 
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