I tried the code below, but now I am getting the error Specified argument was out of the range of valid values.
Parameter name: index?
Private Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
For Each dr In GridView1.Rows
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToString(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(index)
Me.NameTextBox.Text = Server.HtmlDecode(row.Cells(1).Text)
Me.Product1DropDown.SelectedValue = Server.HtmlDecode(row.Cells(2).Text)
Me.Product2DropDown.SelectedValue = Server.HtmlDecode(row.Cells(3).Text)
Me.JobNumberTextBox.Text = Server.HtmlDecode(row.Cells(4).Text)
Me.AdTextBox.Text = Server.HtmlDecode(row.Cells(5).Text)
Me.MediaTypeDropDown.SelectedValue = Server.HtmlDecode(row.Cells(6).Text)
Me.AuthorDropDown.SelectedValue = Server.HtmlDecode(row.Cells(7).Text)
Me.PublicationDropDown.SelectedValue = Server.HtmlDecode(row.Cells(8).Text)
Me.RunDatesTextBox.Text = Server.HtmlDecode(row.Cells(9).Text)
Me.CostTextBox.Text = Server.HtmlDecode(row.Cells(10).Text)
Me.CostCenterTextBox.Text = Server.HtmlDecode(row.Cells(11).Text)
Dim myHyperLink As String = GridView1.DataKeys(dr.RowIndex)("PDFFile")
' do something for each row in the gridview.
Me.HyperLink1.Text = myHyperLink
Me.HyperLink1.NavigateUrl = CType((row.Cells(13).Controls(13)), HyperLink).Text
Me.CommentsTextBox.Text = Server.HtmlDecode(row.Cells(12).Text)
Me.TextBox1.Text = Server.HtmlDecode(row.Cells(14).Text)
Label14.Text = "Update"
End If
Next
End Sub
MKozlowski
Member
500 Points
573 Posts
Re: Unable to read link from gridview?
Apr 30, 2012 12:44 PM|LINK
I tried the code below, but now I am getting the error Specified argument was out of the range of valid values.
Parameter name: index?
Private Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand For Each dr In GridView1.Rows If e.CommandName = "Select" Then Dim index As Integer = Convert.ToString(e.CommandArgument) Dim row As GridViewRow = GridView1.Rows(index) Me.NameTextBox.Text = Server.HtmlDecode(row.Cells(1).Text) Me.Product1DropDown.SelectedValue = Server.HtmlDecode(row.Cells(2).Text) Me.Product2DropDown.SelectedValue = Server.HtmlDecode(row.Cells(3).Text) Me.JobNumberTextBox.Text = Server.HtmlDecode(row.Cells(4).Text) Me.AdTextBox.Text = Server.HtmlDecode(row.Cells(5).Text) Me.MediaTypeDropDown.SelectedValue = Server.HtmlDecode(row.Cells(6).Text) Me.AuthorDropDown.SelectedValue = Server.HtmlDecode(row.Cells(7).Text) Me.PublicationDropDown.SelectedValue = Server.HtmlDecode(row.Cells(8).Text) Me.RunDatesTextBox.Text = Server.HtmlDecode(row.Cells(9).Text) Me.CostTextBox.Text = Server.HtmlDecode(row.Cells(10).Text) Me.CostCenterTextBox.Text = Server.HtmlDecode(row.Cells(11).Text) Dim myHyperLink As String = GridView1.DataKeys(dr.RowIndex)("PDFFile") ' do something for each row in the gridview. Me.HyperLink1.Text = myHyperLink Me.HyperLink1.NavigateUrl = CType((row.Cells(13).Controls(13)), HyperLink).Text Me.CommentsTextBox.Text = Server.HtmlDecode(row.Cells(12).Text) Me.TextBox1.Text = Server.HtmlDecode(row.Cells(14).Text) Label14.Text = "Update" End If Next End Sub