开发者

How to retrieve the selected row value using command row in gridview?

i have a button in gridview whose command name is "hold" i want when i click n hold button of first row then the whole row values will be transfererd to default2.aspx ...

and if i click the hold button of gridview second row then the second row value will be transferred to Default2.aspx ,,how to do that ?

i m using that ...but it always transfer the 1st row value even i select first last or middle row ..in gridview ....

whats wrong in this code ?

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        For Each myRow As GridViewRow In GridView1.Rows
            'Find the checkbox
            Dim lab5 As Label = DirectCast(myRow.FindControl("Label5"), Label)
            If e.CommandName = "feedback" Then
                Me.Response.Redirect("~/view_feedback.aspx?" & "serv_code=" & lab5.Text.ToString)
       开发者_Python百科     End If
        Next
    End Sub


...assuming your posting back the whole page and not using ajax the GridView1_RowCommand will be fired whenever your hold button is clicked, immediately.

As your code is written now you're trying to loop through all rows, and parsing them in turn. However, you are redirecting to your view_feedback.aspx page on the first row if your commandname is Feedback. The first row will be the only one ever processed because your redirect moves the current web request's execution to the new page.

Pass the row index to your command in the CommandArgument property as specified in this example and use it rather than looping through all rows (if you're only processing a single row upon button click anyway).


try this code

 Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
     If e.CommandName = "feedback" Then
         Dim index As Integer = Convert.ToInt32(e.CommandArgument)
         Dim myRow As GridViewRow = GridView1.Rows(index)
         Dim lab5 As Label = DirectCast(myRow.FindControl("Label5"), Label)
         Me.Response.Redirect("~/view_feedback.aspx?" & "serv_code=" & lab5.Text.ToString)
     End If
 End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜