简体   繁体   English

如何使用ASP.NET从网格视图中选择一行并在新的Web表单中编辑详细信息

[英]How to select a row from grid view and edit the details in a new webform using ASP.NET

I have displayed some fields in grid view, Now i want to select a row and i want to display all field from sql server in to a web form, after displaying the data in respective controls(textbox, dropdown), i want to update it. 我已经在网格视图中显示了一些字段,现在我想选择一行,并且要在从SQL Server到Web窗体中显示所有字段,在各个控件(文本框,下拉列表)中显示数据后,我想对其进行更新。

How i can redirect the page to new webpage after selecting the respective row from grid view (Using primary key). 从网格视图中选择相应的行后,如何将页面重定向到新网页(使用主键)。 and how the data will be pass on page load in respective fields so i could able to update it by using update query. 以及如何在各个字段中的页面加载时传递数据,以便我能够使用更新查询来更新它。

As i new to ASP. 当我刚接触ASP时。 Net. 净。 Please update me in detail. 请详细更新我。 If possible please with code. 如果可能,请提供代码。

It would go something like this. 它会像这样。

  1. You will make a 'list' webform with all records containing the gridview 您将创建一个“列表”网络表单,其中所有记录都包含gridview
  2. Make another webform called details 制作另一个称为详细信息的网络表单
  3. The gridview on list page will contain a hyperlink button field something like this 列表页面上的gridview将包含一个超链接按钮字段,如下所示
 <asp:HyperLinkField Text="View Details" DataNavigateUrlFields="YourId" DataNavigateUrlFormatString="details.aspx?id={0}" /> 

(Notice I am just redirecting to the details page passing the field id with querystring. (注意,我只是重定向到详细信息页面,并使用querystring传递字段ID。

  1. Now, on details page you would just fetch the querystring value & query your database with a datareader & populate your details page. 现在,在详细信息页面上,您只需获取querystring值并使用数据读取器查询数据库并填充详细信息页面。 Something like on page load 类似于页面加载
  if(Request.QueryString["id"])!=null) { // Fetch respective item from database here & populate form fields // Open connection(); execute datareader;populate form fields } 

Easiest way to do this: 最简单的方法:

<asp:GridView ID="grd" runat="server" autogeneratedcolumn="false">
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HaderText="Edit">
<ItemTemplate>
<a href='EditData.aspx?ID=<%#Eval("ID")%>'>Edit</a> 
</ItemTemplate>
<asp:TemplateField>
<asp:GridView>

EditData.aspx page will be used to edit the data. EditData.aspx页将用于编辑数据。 After receiving the Query-string Value,we can bind the data to the controls and then update the data after making changes. 收到查询字符串值后,我们可以将数据绑定到控件,然后在进行更改后更新数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM