How To apply color for rows in girid view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Satish Reddy
    New Member
    • Mar 2008
    • 1

    How To apply color for rows in girid view

    hi,

    i have agridview with 100 rows. i need to apply color for row index >50.

    thanx
  • gagandeepgupta16
    New Member
    • Feb 2007
    • 56

    #2
    hey buddy,

    just go into rowdatabound event of the gridview and there check if row index > 50 the set the style row(index).rowc olor = "red"

    this is only a logic, please do the needfull

    thanks

    Originally posted by Satish Reddy
    hi,

    i have agridview with 100 rows. i need to apply color for row index >50.

    thanx

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by gagandeepgupta1 6
      hey buddy,

      just go into rowdatabound event of the gridview and there check if row index > 50 the set the style row(index).rowc olor = "red"

      this is only a logic, please do the needfull

      thanks
      I think what he meant is if it's over 50, to add color to any index greater than 50....


      In your RowDataBound event keep track of how many rows have been added:
      [code=vbnet]
      Private numRows As Integer = 0

      '....

      Protected Sub MyGridView_RowD ataBound(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles MyGridView.RowD ataBound
      numRows+=1
      If numRows>50
      For i As Integer=0 to e.Row.Cells.Cou nt -1
      e.Row.Cells(i). Style.Add("colo r","red")
      Next
      End If
      End Sub
      [/Code]

      -Frinny

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        What Gag said was right, you don't need to keep an extra counter.
        e.Row.RowIndex
        will give you the row index, so you could check against that.
        You can also apply the style to the row as a whole
        [code=vbnet]
        Protected Sub MyGridView_RowD ataBound(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles MyGridView.RowD ataBound
        If e.Row.RowIndex> 50
        e.Row.Style.Add ("color","re d")
        End If
        End Sub
        [/code]

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by Plater
          What Gag said was right, you don't need to keep an extra counter.
          e.Row.RowIndex
          will give you the row index, so you could check against that.
          You can also apply the style to the row as a whole
          [code=vbnet]
          Protected Sub MyGridView_RowD ataBound(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Grid ViewRowEventArg s) Handles MyGridView.RowD ataBound
          If e.Row.RowIndex> 50
          e.Row.Style.Add ("color","re d")
          End If
          End Sub
          [/code]
          Huh....
          Nice :D One less variable to use in my code :D

          -Frinny

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by Frinavale
            Huh....
            Nice :D One less variable to use in my code :D

            -Frinny
            And one less loop :-P

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by Plater
              And one less loop :-P
              Better Yet!

              : )

              Comment

              Working...