asp.net Gridview DataKeyNames

wlwcrazw  于 12个月前  发布在  .NET
关注(0)|答案(1)|浏览(136)

有没有一种方法可以将DataKeyname“Number”包含到响应中。在gridview selectedindexchanged中重定向,以便我可以将其传递到下一页?我目前正在使用此代码传递数据,并且gridview当前设置为在行中显示数字。我想隐藏“number”的列,并使用datakeyname代替。谢谢!

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)

字符串

0vvn1miw

0vvn1miw1#

由于您处于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

字符串

相关问题