Visual Studio Web 开发人员 (C#) - GridView 和 FormView

发布于 2025-01-06 07:11:06 字数 2337 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2025-01-13 07:11:06
 <asp:Panel ID="pnlAddPropertyDetails" runat="server" CssClass="ui-dialog ui-widget ui-widget-content ui-corner-all"
        Width="400" EnableViewState="True">
        <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
            <span class="ui-dialog-title">
                Add Property Details</span>
            <a class="ui-dialog-titlebar-close ui-corner-all"></a>
        </div>
        <div class="ui-dialog-content ui-widget-content">
            //ur content of dialog here
        </div>
    </asp:Panel>

不要忘记添加 jquery 的 css 文件来利用它们的类

 <asp:Panel ID="pnlAddPropertyDetails" runat="server" CssClass="ui-dialog ui-widget ui-widget-content ui-corner-all"
        Width="400" EnableViewState="True">
        <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
            <span class="ui-dialog-title">
                Add Property Details</span>
            <a class="ui-dialog-titlebar-close ui-corner-all"></a>
        </div>
        <div class="ui-dialog-content ui-widget-content">
            //ur content of dialog here
        </div>
    </asp:Panel>

do not forget to add css file of jquery to leverage their classes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文