如何将数据行添加到GridView数据库?

时间:2013-05-22 21:21:10

标签: c# asp.net mysql

我一直在互联网上搜索我对这个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>

1 个答案:

答案 0 :(得分:0)

在这里你可以找到一个线索:

How to easily insert row in GridView with SqlDataSource?