Getting Text from rows of gridview


R

rhoenig

I have a gridview that is populated from a SortedList. In the
gridview I have a text box that the user can update, when they click
update I want to remove the entry from the list and readd it with the
updated item. My problem is when I try to get the text that is in the
cells of the gridview it returns nothing. I remove the item from the
list and that works fine so I know it's getting the proper row.

Here's my code. I found most of this on Microsoft's site.

<code>
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' Retrieve the row that contains the button clicked
' by the user from the Rows collection.
Dim row As GridViewRow = destServersView.Rows(index)

' Create a new ListItem object for the Server Name in the
row.
Dim sName As New ListItem()
sName.Text = Server.HtmlDecode(row.Cells(0).Text)

' Create a new ListItem object for the Destination Folder
in the row.
Dim sDestFolder As New ListItem()
sDestFolder.Text = Server.HtmlDecode(row.Cells(1).Text)

Me.serverList.Remove(selectedIndex.ToString)
Me.serverList.Add(selectedIndex.ToString, sName.ToString &
"; " & sDestFolder.ToString)
</code>

Any suggestions.

Thanks
Robert
 
Ad

Advertisements

G

Guest

Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' Retrieve the row that contains the button clicked
' by the user from the Rows collection.
Dim row As GridViewRow = destServersView.Rows(index)

That's fine

' Create a new ListItem object for the Server Name in the
row.
Dim sName As New ListItem()
sName.Text = Server.HtmlDecode(row.Cells(0).Text)

Is it a place where you have a problem?
try to debug the code...

simply add as follows:

Response.Write "row.Cells(0)=" & Server.HtmlDecode(row.Cells(0))

It should return a result.
' Create a new ListItem object for the Destination Folder
in the row.
Dim sDestFolder As New ListItem()
sDestFolder.Text = Server.HtmlDecode(row.Cells(1).Text)


Add

Response.Write "row.Cells(0)=" & Server.HtmlDecode(row.Cells(1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top