• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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.
0
RobAinscough
Asked:
RobAinscough
1 Solution
 
iboutchkineCommented:
do it like this

        Dim iSelectedRow As Integer = 2
        gv.SelectedIndex = iSelectedRow
        Label1.Text =  gv.SelectedRow.Cells(6).Text
0
 
RobAinscoughAuthor Commented:
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.
0
 
aponcealbuerneCommented:
Hi well i had the same problem and to work around it I made the field a  TemplateField


Hope helps
0
 
GranModCommented:
PAQed with points refunded (125)

GranMod
Community Support Moderator
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now