Link to home
Start Free TrialLog in
Avatar of ppeterso
ppetersoFlag for United States of America

asked on

How to access gridview DataRow field to conditionally set Gridview Header field

I have a gridview.  One of my dataRow fields holds either an "H" or a "D" value to indicate "Hours" or "Days".    I want to display "Hours" or "Days" in the header based on the dataRow field value.

Is there a way to determine the value of the dataRow field when the gridview is processing the Header row?  

 if (e.Row.RowType == DataControlRowType.Header)
            {
                if (e.Row.Cells[2].Text.Contains("H"))  This is the datarow field value I'm trying to access (this doesn't work)

Avatar of strickdd
strickdd
Flag of United States of America image

1. create an OnDataBound event for the gridview.
2. Then, assuming all no row can have an "H" when another row contains a "D", look at the first row
3. If the first row has an "H" change the gridview header row column
4. Do the same if the row has a "D"
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial