-1

我一直在互联网上搜索我是这个 C# 和 asp.net 的新手,如何在 Gridview 添加新行和插入数据?我已经成功地将它附加到我的数据库中。当我尝试使用 ListView 时,我可以使用插入数据功能来实现,但显示不足以显示我的所有数据表。我四处寻找,不知道如何处理背后的代码。我对这些完全陌生,我需要这样做才能提交我的作业。请帮助我。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ResinPrice.aspx.cs" Inherits="MQM_System.ResinPrice" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        DataSourceID="SqlDataSource1" AllowSorting="True" 
        AutoGenerateColumns="False" DataKeyNames="SN">
        <Columns>

            <asp:BoundField DataField="SN" HeaderText="SN" ReadOnly="True" 
                SortExpression="SN" />
            <asp:BoundField DataField="MaterialDescription" 
                HeaderText="MaterialDescription" SortExpression="MaterialDescription" />
            <asp:BoundField DataField="Location" HeaderText="Location" 
                SortExpression="Location" />
            <asp:BoundField DataField="PreviousUpdate" HeaderText="PreviousUpdate" 
                SortExpression="PreviousUpdate" />
            <asp:BoundField DataField="DateUpdate" HeaderText="DateUpdate" 
                SortExpression="DateUpdate" />
            <asp:BoundField DataField="25kg" HeaderText="25kg" SortExpression="25kg" />
            <asp:BoundField DataField="100kg" HeaderText="100kg" SortExpression="100kg" />
            <asp:BoundField DataField="250kg" HeaderText="250kg" SortExpression="250kg" />
            <asp:BoundField DataField="500kg" HeaderText="500kg" SortExpression="500kg" />
            <asp:BoundField DataField="1ton" HeaderText="1ton" SortExpression="1ton" />
            <asp:BoundField DataField="2ton" HeaderText="2ton" SortExpression="2ton" />
            <asp:BoundField DataField="5ton" HeaderText="5ton" SortExpression="5ton" />
            <asp:BoundField DataField="10ton" HeaderText="10ton" SortExpression="10ton" />
            <asp:BoundField DataField="25ton" HeaderText="25ton" SortExpression="25ton" />
            <asp:BoundField DataField="Mfr" HeaderText="Mfr" SortExpression="Mfr" />

        </Columns>
    </asp:GridView>


    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:flextronic singaporeConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:flextronic singaporeConnectionString.ProviderName %>" 
        SelectCommand="SELECT * FROM resin_price" 
        DeleteCommand="DeleteCommand=&quot;DELETE FROM resin_price WHERE S/N = ?&quot; " 
        InsertCommand="InsertCommand=&quot;INSERT INTO resin_price (SN, Material_Description, Location, Previous_Update, Date_Update, 25kg, 100kg, 250kg, 500kg, 1ton, 2ton, 5ton, 10ton, 25ton, Mfr) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)&quot; " 
        UpdateCommand="UpdateCommand=&quot;UPDATE resin_price SET Material_Description = ?, Location = ?, Previous_Update = ?, Date_Update = ?, 25kg = ?, 100kg = ?, 250kg = ?, 500kg = ?, 1ton = ?, 2ton = ?, 5ton = ?, 10ton = ?, 25ton = ?, Mfr = ? WHERE SN = ?&quot;&gt;"></asp:SqlDataSource>

</asp:Content>
4

1 回答 1

0

在这里,您可以找到执行此操作的线索:

如何使用 SqlDataSource 在 GridView 中轻松插入行?

于 2013-05-22T22:20:32.707 回答