anthony6482
asked on
GridView problem with hidden field object using gridview
I have a gridview object that contains a hidden field component to store idValue from a database.
When I make a for loop cycle to read the value of this hidden field, I can't read the first value (index 0) but I CAN read the other values.
The code I'm using is very simple:
Dim x As Integer = 0
For x = 0 To gvCleanAer.Rows.Count - 1
Select Case x
Case 0
Session("CleanAerBreeze") = CType(gvCleanAer.Rows(x).C ells(0).Co ntrols(1), HiddenField).Value() & ";" & CInt(CType(gvCleanAer.Rows (x).Cells( 3).Control s(1), TextBox).Text)
Case 1
Session("CleanAerNature") = CType(gvCleanAer.Rows(x).C ells(0).Co ntrols(1), HiddenField).Value() & ";" & CInt(CType(gvCleanAer.Rows (x).Cells( 3).Control s(1), TextBox).Text)
Case 2
Session("CleanAerOrchand") = CType(gvCleanAer.Rows(x).C ells(0).Co ntrols(1), HiddenField).Value() & ";" & CInt(CType(gvCleanAer.Rows (x).Cells( 3).Control s(1), TextBox).Text)
Case 3
Session("CleanAerPersian") = CType(gvCleanAer.Rows(x).C ells(0).Co ntrols(1), HiddenField).Value() & ";" & CInt(CType(gvCleanAer.Rows (x).Cells( 3).Control s(1), TextBox).Text)
End Select
Next
If i change the HiddenField object into a textbox every value can be read correctly without any problem. Please help!
When I make a for loop cycle to read the value of this hidden field, I can't read the first value (index 0) but I CAN read the other values.
The code I'm using is very simple:
Dim x As Integer = 0
For x = 0 To gvCleanAer.Rows.Count - 1
Select Case x
Case 0
Session("CleanAerBreeze") = CType(gvCleanAer.Rows(x).C
Case 1
Session("CleanAerNature") = CType(gvCleanAer.Rows(x).C
Case 2
Session("CleanAerOrchand")
Case 3
Session("CleanAerPersian")
End Select
Next
If i change the HiddenField object into a textbox every value can be read correctly without any problem. Please help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you can use invisble boundcolumn instead of hidden field - BoundColumn.Visible = False. Then you can get the value like this:
Response.Write(gvCleanAer. Rows(x).Ce lls(3).Tex t)
Response.Write(gvCleanAer.
In Asp.Net no values can be read out from the hidden fields. Instead, you change the hidden field to label and set the forecolor of the label equivalent to the background color of each grid row. But better you mind do you have different formatting for Item and AlternateItem rows.
In this way, you can read values by using the same FindControl method, from the label which is invisible.
- Suresh
In this way, you can read values by using the same FindControl method, from the label which is invisible.
- Suresh
style="display: none" will have the same effect as setting the background colour, but with the benefits that you don't have to mess around working out what colour the background is, and your key values won't be displayed to anyone cursor-selecting that part of your HTML.
foreach (GridViewRow row in gridView1.Rows)
{
HiddenField hid = (HiddenField)row.FindContr
}
Hope this helps.
Steve