Click here to Skip to main content
15,900,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a datarow before binding the gridview.
this is my code :
C#
DataTable dt1 = objAttendees.fetch_attendeesforSupplier();
      if (dt1.Rows.Count > 0)
      {
          DataRow dr = dt1.NewRow();

          //DataRow dr = style.'background: #EEE9F8;';
          dr["CompanyName"] = Convert.ToString(dt1.Rows[0]["CompanyName"]);
          dr["keyfullname"] = Convert.ToString(dt1.Rows[0]["keyfullname"]);
          dr["Email"] = Convert.ToString(dt1.Rows[0]["Email"]);
          dr["attendeesfullname"] = Convert.ToString(dt1.Rows[0]["keyfullname"]);
          dr["attendeesemail"] = Convert.ToString(dt1.Rows[0]["Email"]);
          dr["CreatedDate"] = Convert.ToString(dt1.Rows[0]["CreatedDate"]);
          dr["TransactionType"] = Convert.ToString(dt1.Rows[0]["TransactionType"]);

          dt1.Rows.Add(dr);

          dt1.AcceptChanges();

          gdSupplier.DataSource = dt1;
          gdSupplier.DataBind();
     }

now i want to give a color to that datarow only...how to do this in c#?
please help me out
Posted
Updated 7-Feb-14 1:23am
v4

Hi,

C#
protected void gvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// put your condition, based on that apply the color
}

}
 
Share this answer
 
Comments
Member 10276220 7-Feb-14 6:46am    
how to give that condition?
Hi,

try this
link1
link2
 
Share this answer
 
see this example for that

C#
protected void GVRate_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       try
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               DateTime dtdate = DateTime.ParseExact(e.Row.Cells[1].Text, "dd/MM/yyyy", null);

               if (dtdate == DateTime.Now.Date)
               {
                   e.Row.BackColor = Color.FromName("#00B5D0");
               }
           }
       }
       catch (Exception ex)
       {
          
       }
   }


it is based on today date condition..like you enter some condition..
 
Share this answer
 
Comments
Member 10276220 7-Feb-14 6:57am    
i use a datarow...i need to give color to that dr...how to do this?
Siva Hyderabad 7-Feb-14 7:01am    
dararow or datatable any one. you must go gridview Row Databound event...
Member 10276220 7-Feb-14 7:03am    
please see my code...in that case how to write the syntax?
please help...
Siva Hyderabad 7-Feb-14 7:29am    
try this after
DataRow dr = dt1.NewRow();
e.Row.BackColor = Drawing.Color.Red;
Siva Hyderabad 7-Feb-14 7:41am    
it's ok na?

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