Visual Studio Web 开发人员 (C#) - GridView 和 FormView
我在 Visual Web Developer (ASP.NET - C#) 中有这个作业,不幸的是我没有足够的时间在截止日期之前正确地研究所有内容 - 我必须创建 GridView 以便它显示数据库中的数据。我遇到的问题是:
当我单击连续的“编辑”按钮时,我应该进入“FormView 的编辑模式”或类似的内容,而不是“GridView 的编辑模式”(所以在单击“编辑”后,我应该只看到相应表记录的 gridview 的每一列有 1 行的表单,而不是仅将一行记录更改为 TextBox 的相同 Gridview ...)。
请像这样考虑 Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id_people" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id_people" HeaderText="id_people" ReadOnly="True"
SortExpression="id_people" />
<asp:BoundField DataField="first_name" HeaderText="first_name"
SortExpression="first_name" />
<asp:BoundField DataField="last_name" HeaderText="last_name"
SortExpression="last_name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:InsertRowsWithGridViewConnectionString1 %>"
SelectCommand="SELECT [id_people], [first_name], [last_name] FROM [Table1]"
UpdateCommand="UPDATE [Table1] SET [first_name] = @first_name, [last_name] = @last_name WHERE [id_people] = @id_people">
<UpdateParameters>
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="id_people" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
I have this homework in Visual Web Developer (ASP.NET - C#) and unfortunately I have not enough time to the deadline to study everything properly - I have to create GridView so it shows data in database. The problem I have is:
When I click on Edit button in a row I am supposed to go to "Edit mode of FormView" or to something that looks like that instead of "Edit mode of GridView" (so after clicking on Edit I am supposed to see only a form with 1 line for each column of gridview of the appropriate table record, not the same Gridview with just changed records of one line to TextBoxes...).
Consider Default.aspx like this please:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id_people" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id_people" HeaderText="id_people" ReadOnly="True"
SortExpression="id_people" />
<asp:BoundField DataField="first_name" HeaderText="first_name"
SortExpression="first_name" />
<asp:BoundField DataField="last_name" HeaderText="last_name"
SortExpression="last_name" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:InsertRowsWithGridViewConnectionString1 %>"
SelectCommand="SELECT [id_people], [first_name], [last_name] FROM [Table1]"
UpdateCommand="UPDATE [Table1] SET [first_name] = @first_name, [last_name] = @last_name WHERE [id_people] = @id_people">
<UpdateParameters>
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="id_people" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要忘记添加 jquery 的 css 文件来利用它们的类
do not forget to add css file of jquery to leverage their classes