Link to home
Start Free TrialLog in
Avatar of RobAinscough
RobAinscough

asked on

WebControl.GridView bug?

I'm trying to retrieve a value I placed in a grid view column that is set to NOT visible:

gv_Units is the GridView control

Dim gvRow As GridViewRow
For Each gvRow In gv_Units.Rows

    Dim someValue as string = gvRow.Cells(6).Text

Next gvRow

If column 6 is not visible SomeValue = ""
If column 6 is visible SomeValue = "myvalue"

Is this a known bug with GridView?  Please tell me this is NOT a "design feature".  Any workarounds?

Thanks, Rob.
Avatar of iboutchkine
iboutchkine

do it like this

        Dim iSelectedRow As Integer = 2
        gv.SelectedIndex = iSelectedRow
        Label1.Text =  gv.SelectedRow.Cells(6).Text
Avatar of RobAinscough

ASKER

Being a selected row is not relevant.

I discovered the solution, setup a CSS style (i.e. NoVisibleText) that is "display:none" -- assign the CSSClass for each of the column properties (i.e. ControlStyle.CSSClass = NoVisibleText, ItemStyle.CSSClass = NoVisibleText, HeaderStyle.CSSClass = NoVisibleText, FooterStyle.CSSClass = NoVisibleText) -- Keep the Column Visible property = True (this must be true or the cell value can never be retreived).

Rob.
Avatar of aponcealbuerne
Hi well i had the same problem and to work around it I made the field a  TemplateField


Hope helps
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

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