如何使用按钮点击更改asp网格中的gridview行颜色?

问题描述:

这是我的数据绑定方法

This is My databind Method

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;
               }

           }

您好



请尝试以下代码。



Hi

Try the below code .

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;
    }
}


更改特定行的颜色时:

1)。 GridView1.Rows [0] .BackColor = System.Drawing.Color.Red;



当改变所有偶数和奇数行颜色时:



2)。 GridView1.RowStyle.BackColor = System.Drawing.Color.Red;

GridView1.AlternatingRowStyle.BackColor = System.Drawing.Color.Blue;
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;


如下所示

Do like below
if(yourcondition)
{
GridView1.RowStyle.BackColor = System.Drawing.Color.White;
}
else
{
GridView1.RowStyle.BackColor = System.Drawing.Color.Aqua;
}