Вопрос

I was trying fire a row data bind event to a grid view. When data is being bound to grid view, i would like to check a condidtion , if the condidtion is satisfied , then i need to apply some color to that entire row..Please check the below code i am using..

protected void GridView4_RowDataBound(object sender, GridViewRowEventArgs e)
{

  if (e.Row.RowType == DataControlRowType.DataRow)
   {

    Textbox txtBox1 = (GridView)(e.Row.FindControl("Name of text box"));

      if(Condidtion)
      {
          txtBox1.enabled=false;
          txtBox1.bgcolor=somecolor;
      } 

   }

}

Please help me on this..

Это было полезно?

Решение

below will change the color of row

  if(Condidtion)
  {
      e.Row.BackColor =somecolor;
  } 

Другие советы

Your code is specifically selecting one textBox. If you want to apply the condition to all the elements in the row you need to iterate through the controls on the row rather than selecting one and run that condition on each.

It would probably be easier to do this in JavaScript because drawing on a grid and maintaining state between postbacks is more complex.

you can set background color like this

rows[i].BackColor = System.Drawing.Color.RoyalBlue;

or you can set your defined color like bellow

rows[i].BackColor = "#fff23";

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top