Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is My databind Method
C#
DateTime fldate = DateTime.Parse(txtflightDate.Text);
              String refcode = DropdownRefcode.SelectedItem.Text.ToString().Trim();
              dt = ML.getMainfestAll(fldate, refcode);

              if (dt != null && dt.Rows.Count > 0)
              {
                  GridViewml.DataSource = dt;//
                  GridViewml.DataBind();

              }

I need to add This is Method databind time how do it.any one can help me.

DataTable NEW = new DataTable();
           for (int i = 0; i < GridViewml.Rows.Count; i++)//
           {

               String hawb = GridViewml.Rows[i].Cells[1].Text;//1
               NEW = ML.getsatlisting(hawb);
               if (NEW != null && NEW.Rows.Count > 0)
               {
                             White;//
               }

               else
               {
                             SkyBlue;
               }

           }
Posted
Updated 26-Nov-13 23:44pm
v2
Comments
JoCodes 27-Nov-13 5:45am    
Where is your button?
Rahul_Pandit 27-Nov-13 5:51am    
If ur button is inside griview it then u have to register onclick of button on rowdatabound of gridview..and call method of javascipt..
[no name] 27-Nov-13 5:58am    
Not inside a griview

Hi

Try the below code .

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    int rowIndex = Convert.ToInt32(e.CommandArgument);


    foreach (GridViewRow row in GridView1.Rows)
    {
        row.BackColor = row.RowIndex.Equals(rowIndex) ?
            System.Drawing.Color.Red :
            System.Drawing.Color.White;
    }
}
 
Share this answer
 
When change the color of a perticular row:
1). GridView1.Rows[0].BackColor = System.Drawing.Color.Red;

When change the All even and odd row color:

2). GridView1.RowStyle.BackColor = System.Drawing.Color.Red;
GridView1.AlternatingRowStyle.BackColor = System.Drawing.Color.Blue;
 
Share this answer
 
Do like below
C#
if(yourcondition)
{
GridView1.RowStyle.BackColor = System.Drawing.Color.White;
}
else
{
GridView1.RowStyle.BackColor = System.Drawing.Color.Aqua;
}
 
Share this answer
 
v3

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