GridView color change depending on inner value

rotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          // This line will get the reference to the underlying row
          DataRowView _row = (DataRowView)e.Row.DataItem;
          if (_row != null)
          {
              // get the field value which you want to compare and
               // convert to the corresponding data type
               // i assume the fieldName is of int type
              int _field = Convert.ToInt32(_row.Row["fieldName"]);
              if (_field == 7)
                  e.Row.BackColor = System.Drawing.Color.Green;
              else
                  e.Row.BackColor = System.Drawing.Color.Red;
          }
      }
  }
Reactions

Post a Comment

3 Comments

  1. what is data is binded using linq in gridview....then we dnt find column name

    ReplyDelete
  2. Hi ekta
    Yes u can.check this post i have created a demo application
    http://aspdotnetcodebook.blogspot.com/2010/05/how-to-bind-gridview-using-linq-join.html

    ReplyDelete

Please do not post any spam link in the comment box😊

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)

Close Menu