用GRIDVIEW显示查询结果,然后点编辑另起一页进行编辑?求方法.
小弟用VS2005,ASP2.0和VB.NET进行编写.
现在碰到个问题,我查询代码自己写的,显示在GRIDVIEW里面,然后在GRIDVIEW里面添加编辑按钮,然后联接到另外一个页面把选中的内容详细的列出来进行编辑,求方法.
我的代码是:
查询:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnectionString As String
myConnectionString = "server=localhost;database=NBDC;uid=****;pwd=****; "
Dim myConnection As New SqlConnection(myConnectionString)
Dim mySelect As String = "SELECT * FROM Repository WHERE Name LIKE '% " + TextBox3.Text + "% ' AND Operator LIKE '% " + DropDownList1.Text + "% ' AND Type LIKE '% " + DropDownList2.Text + "% ' AND Server LIKE '% " + DropDownList3.Text + "% ' AND Detail LIKE '% " + TextBox4.Text + "% ' AND Keyword LIKE '% " + TextBox6.Text + "% ' "
Dim myCommand As New SqlCommand(mySelect)
Dim adapter As SqlDataAdapter = New SqlDataAdapter(mySelect, myConnection)
myCommand.Connection = myConnection
myConnection.Open()
Dim ds As New DataSet
adapter.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
myCommand.Connection.Close()
End Sub
显示:
<asp:GridView ID= "GridView1 " runat= "server " AllowPaging= "True " Width= "780px " Font-Size= "Small " ForeColor= "Black " AutoGenerateColumns= "False " DataKeyNames= "RepositoryID " AutoGenerateDeleteButton= "True " AutoGenerateEditButton= "True " EnableSortingAndPagingCallbacks= "True " PageSize= "8 ">
<Columns>
<asp:BoundField DataField= "Name " HeaderText= "名称 "> </asp:BoundField>
<asp:BoundField DataField= "Operator " HeaderText= "操作者 "> </asp:BoundField>
<asp:BoundField DataField= "Type " HeaderText= "类型 "> </asp:BoundField>
<asp:BoundField DataField= "Datetime " HeaderText= "时间 "> </asp:BoundField>
<asp:BoundField DataField= "Detail " HeaderText= "描述 "> </asp:BoundField>
<asp:BoundField DataField= "Picture " HeaderText= "图片 "> </asp:BoundField>
<asp:BoundField DataField= "Keyword " HeaderText= "关键字 "> </asp:BoundField>
<asp:BoundField DataField= "Server " HeaderText= "服务器 "> </asp:BoundField>
<asp:HyperLinkField HeaderText= "编辑 " Text= "编辑 " DataNavigateUrlFormatString= "SearchEdit.aspx?RepositoryID={0} " DataNavigateUrlFields= "RepositoryID "> </asp:HyperLinkField>
<asp:CommandField ShowEditButton= "True " />
</Columns>
</asp:GridView>
后面我的思路是:点编辑以后,联接到SearchEdit.aspx页面,然后把相应的数据详细的显示在页面上,然后用UPDATING 命令进行更新,求每个环节,特别是把选中的行的信息怎么关联到下一个页面的代码.先谢谢了.
[解决办法]
你把ID这条记录的ID传过去了不就解决了么
在编辑也面根据获取的ID来取着条记录的详细信息,生成一个DataTable 数据集,然后在页面显示
这些信息,显示在TextBox里面,更新的时候执行UPdate语句就可以了撒
[解决办法]
晕
Request.QueryString[ "RepositoryID "]
这个就是你的RepositoryID
[解决办法]
下个页面用Request.QueryString[ "RepositoryID "]或Request.QueryString[0]
上面是C#,自己换成VB.NET的写法,应该是差不多一样,我不知道VB.Net是0开始还是1开始索引,是中括号还是小括号,是双引号单引号~~
[解决办法]
在 SearchEdit.aspx 里面的 Page_load :
使用String strID=Request.[ "RepositoryID "].ToString();不就取值过来了么 ..
我写的是C#
[解决办法]
先在DataKeyNames中存入你想传递的值对应的字段,通常用主键.
然后
[C#]
DataKey key = this.GridView1.DataKeys[e.RowIndex];
String var=key[0].ToString();
取得这个值,就可以实现想要的update操作了.
[解决办法]
Request[ "RepositoryID "]