2014-01-09 60 views
1

有沒有辦法將DataKeyname「Number」包含到gridview selectedindexchanged中的response.redirect中,以便我可以將它傳遞到下一頁?我目前使用這個代碼來傳遞數據,並且gridview目前被設置爲顯示行中的數字。我想隱藏「數字」列並改爲使用datakeyname。謝謝!Gridview DataKeyNames

Response.Redirect("RoundingEntry.aspx?Room=" & GridView1.SelectedRow.Cells(1).Text & "&Name=" & GridView1.SelectedRow.Cells(2).Text & "&Number=" & GridView1.SelectedRow.Cells(3).Text & "&Member=" & DDMember.SelectedValue & "&Unit=" & DDUnit.SelectedValue) 

回答

0

既然你在SelectedIndexChanged事件的時候,你可以使用GridView.SelectedIndex屬性來獲取寫入數據的關鍵出GridView.DataKeys收藏。

也許我還建議清理它,這樣它不是一個長長的代碼行?

Sub CustomersGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
    Dim room As String = GridView1.SelectedRow.Cells(1).Text 
    Dim name As String = GridView1.SelectedRow.Cells(2).Text 
    ' This is the one I've changed, to grab the DataKey of the selected row 
    Dim number As String = GridView1.DataKeys(GridView1.SelectedIndex).Value.ToString() 
    Dim member As String = DDMember.SelectedValue.ToString() 
    Dim unit As String = DDUnit.SelectedValue.ToString() 

    Response.Redirect("RoundingEntry.aspx?Room=" & room & _ 
             "&Name=" & name & _ 
             "&Number=" & number & _ 
             "&Member=" & member & _ 
             "&Unit=" & unit) 
End Sub 
+1

謝謝。作品! – user3119778

+0

沒問題,@ user3119778!我很高興能夠提供幫助。並感謝對勾=) – jadarnel27

相關問題