jvoconnell
asked on
Get a value from a gridview cell
Experts,
Newbie question:
I cannot get a value from a cell in a gridview. The gridview loads properly. The first column is a template column with a checkbox. I am able to check whether the user selects the checkbox or not. But I am unable to get any vaule from any other cells in that row.
I try to use: gridview1.SelectedRow.Cell s(2).Text to get the value I want.
I get a NullReference Exception was unhandled by user code error.
The gridview has 6 columns. The first is the checkbox column and the other 5 all have data populated in them.
Newbie question:
I cannot get a value from a cell in a gridview. The gridview loads properly. The first column is a template column with a checkbox. I am able to check whether the user selects the checkbox or not. But I am unable to get any vaule from any other cells in that row.
I try to use: gridview1.SelectedRow.Cell
I get a NullReference Exception was unhandled by user code error.
The gridview has 6 columns. The first is the checkbox column and the other 5 all have data populated in them.
Try this
For iRow As Integer = 0 To GridView1.Rows.Count - 1
Dim chkBox As New CheckBox()
chkBox = DirectCast(GridView1.Rows(iRow).FindControl("mycheckbox"), CheckBox)
If chkBox.Checked Then
string str = Gridview1.Rows(iRow).Cells(1).ToString()
End If
Next
put a breakpoint on this line
add this to watch "gridview1.SelectedRow.Cel ls", browse all properties to understand it
and open immediate window and put
?gridview1.SelectedRow.Cel ls
?gridview1.SelectedRow.Cel ls.Count
?gridview1.SelectedRow.Cel ls(0).Text
?gridview1.SelectedRow.Cel ls(1).Text
?gridview1.SelectedRow.Cel ls(2).Text
add this to watch "gridview1.SelectedRow.Cel
and open immediate window and put
?gridview1.SelectedRow.Cel
?gridview1.SelectedRow.Cel
?gridview1.SelectedRow.Cel
?gridview1.SelectedRow.Cel
?gridview1.SelectedRow.Cel
ASKER
HainKurt:
I get "Referenced object has a value of 'Nothing' in the intermdiate window
I get "Referenced object has a value of 'Nothing' in the intermdiate window
when you add this to watch
gridview1.SelectedRow
or
?gridview1.SelectedRow
you get nothing... means no row is selected...
gridview1.SelectedRow
or
?gridview1.SelectedRow
you get nothing... means no row is selected...
maybe you should use this
Dim index As Integer = gridview1.EditIndex
Dim row As GridViewRow = gridview1.Rows(index)
then use
row.Cells(2).Text
Dim index As Integer = gridview1.EditIndex
Dim row As GridViewRow = gridview1.Rows(index)
then use
row.Cells(2).Text
ASKER
Am I making an incorrect assumption that when the checkbox is checked that the row is "selected"?
;) no it is not selected...
check this sample
http://www.codedigest.com/Articles/ASPNET/132_GridView_with_CheckBox_%E2%80%93_Select_All_and_Highlight_Selected_Row.aspx
check this sample
http://www.codedigest.com/Articles/ASPNET/132_GridView_with_CheckBox_%E2%80%93_Select_All_and_Highlight_Selected_Row.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also check this
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/6e29b371de01b72f?hl=en
to select a row with a check box, actually when you click checkbox you will do a post back to select that row...
just another approach...
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/6e29b371de01b72f?hl=en
to select a row with a check box, actually when you click checkbox you will do a post back to select that row...
just another approach...
ASKER
This is it!!!! Thank you for all of the assistance. It is very much appreciated.
Open in new window