我的最终目标是让我的程序像这样工作:
我完成了所有工作,但是,DetailsView只显示数据库表中第一个条目的内容,而不是我按下编辑按钮的条目。
所以我的问题是,如何告诉程序在GridView上编辑哪一行,并获取在DetailsView上创建新select语句的信息(如键)?
TablePage.aspx (仅包含相关代码)
<asp:GridView ID="GridView1" runat="server" OnRowEditing="RowEditing"
AutoGenerateEditButton="True">
<Columns>
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
</Columns>
</asp:GridView>
TablePage.aspx.vb (同样,只有相关代码)
Protected Sub RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
Dim url As String = "/tables/edit.aspx"
Dim s As String = "window.open('" & url + "', 'popup_window', 'width=300,height=300s,left=100,top=100,resizable=yes');"
ClientScript.RegisterStartupScript(Me.GetType(), "script", s, True)
End Sub
答案 0 :(得分:1)
您可以使用RowEditing函数中的 e.NewEditIndex 来获取在GridView中编辑的当前行,获取您可以访问该行并从该行获取任何单元格文本。
请试试这个:
Protected Sub RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
'First, get the current RowIndex
Dim selectedRowIndex As Integer = e.NewEditIndex
'Then get any information you need from the row, for example the name of the first cell
Dim selectedItemText As String = GridView1.Rows(selectedRowIndex).Cells(1).Text
'Now you can store the information in session to use it in other page
Session("EditParameter") = selectedItemText
Dim url As String = "/tables/edit.aspx"
Dim s As String = "window.open('" & url + "', 'popup_window', 'width=300,height=300s,left=100,top=100,resizable=yes');"
ClientScript.RegisterStartupScript(Me.GetType(), "script", s, True)
End Sub
当然,您可以添加另一个包含记录编号的隐藏边界字段,然后访问它而不是名称。
希望这有帮助。