国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

asp.net 2.0中用GRIDVIEW插入新記錄

2019-11-18 19:32:41
字體:
供稿:網(wǎng)友

看了下國外某巨牛的BLOG,大概是講asp.net 2.0中用GRIDVIEW插入新記錄的,方法比較特別,但效果一般,故將程序轉(zhuǎn)之,較為簡單,不做解釋等。
<%@ Page Language="C#" ClassName="Default_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "

<script runat="server">
    void CancelButton1_Click(object sender, EventArgs e)
    {

        GridView1.ShowFooter = false;

    }
    void AddButton1_Click(object sender, EventArgs e)
    {

        GridView1.ShowFooter = true;

    }

    void Button1_Click(object sender, EventArgs e)

    {
       
        TextBox customerID = GridView1.FooterRow.FindControl("CustomerIDTextBox") as TextBox;

        TextBox companyName = GridView1.FooterRow.FindControl("CompanyNameTextBox") as TextBox;

        DropDownList ContactTitle = GridView1.FooterRow.FindControl("ContactTitleDropDownList") as DropDownList;

        SqlDataSource1.InsertParameters["CustomerID"].DefaultValue = customerID.Text;

        SqlDataSource1.InsertParameters["CompanyName"].DefaultValue = companyName.Text;

        SqlDataSource1.InsertParameters["ContactTitle"].DefaultValue = ContactTitle.SelectedValue;

        SqlDataSource1.Insert();

    }
 

</script>

<html xmlns="

<head id="Head1" runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>
    <asp:Button ID="AddButton1" runat="Server" Text="Add new Item" OnClick="AddButton1_Click" />


    <asp:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1" DataKeyNames="CustomerID"

            AutoGenerateColumns="False" ShowFooter="True">

            <Columns>

                <asp:TemplateField>

                    <ItemTemplate>

                        <asp:Label ID="CustomerIDLabel" Runat="Server"><%# Eval("CustomerID") %></asp:Label>

                    </ItemTemplate>

                    <FooterTemplate>

                        <asp:TextBox ID="CustomerIDTextBox" Runat="server"></asp:TextBox>

                    </FooterTemplate>

                </asp:TemplateField>

                <asp:TemplateField>

                    <ItemTemplate>

                        <asp:Label ID="CompanyNameLabel" Runat="Server"><%# Eval("CompanyName") %></asp:Label>

                    </ItemTemplate>

                    <FooterTemplate>

                        <asp:TextBox ID="CompanyNameTextBox" Runat="server"></asp:TextBox>

                    </FooterTemplate>

                </asp:TemplateField>

                <asp:TemplateField>

                    <FooterTemplate>

                        <asp:DropDownList ID="ContactTitleDropDownList" Runat="server" DataSourceID="SqlDataSource2" DataTextField="ContactTitle" DataValueField="ContactTitle">

                        </asp:DropDownList>

                        <asp:SqlDataSource ID="SqlDataSource2" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]"

                            ConnectionString="server=localhost;uid=sa;passWord=xxx;database=northwind">

                        </asp:SqlDataSource>

                        <asp:Button ID="Button1" Runat="server" Text="Add" OnClick="Button1_Click" />
  <asp:Button ID="CancelButton1" Runat="server" Text="Cancel" OnClick="CancelButton1_Click" />

                    </FooterTemplate>

                    <ItemTemplate>

                        <asp:DropDownList ID="ContactTitleDropDown" SelectedValue='<%# Bind("ContactTitle") %>' Runat="Server" DataSourceID="SqlDataSource3" DataTextField="ContactTitle" DataValueField="ContactTitle" ></asp:DropDownList>

                        <asp:SqlDataSource ID="SqlDataSource3" Runat="server" SelectCommand="SELECT DISTINCT [ContactTitle] FROM [Customers]"

                            ConnectionString="server=localhost;uid=sa;password=xxx;database=northwind" EnableCaching="True">

                        </asp:SqlDataSource>

                    </ItemTemplate>

                </asp:TemplateField>

            </Columns>

        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" Runat="server"

            InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactTitle]) VALUES (@CustomerID, @CompanyName, @ContactTitle)"

            SelectCommand="SELECT [CustomerID], [CompanyName], [ContactTitle] FROM [Customers]"

            ConnectionString="server=localhost;uid=sa;password=xxxxx;database=northwind">

            <DeleteParameters>

                <asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>

            </DeleteParameters>

            <UpdateParameters>

                <asp:Parameter Type="String" Name="CompanyName"></asp:Parameter>

                <asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter>

                <asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>

            </UpdateParameters>

            <InsertParameters>

                <asp:Parameter Type="String" Name="CustomerID"></asp:Parameter>

                <asp:Parameter Type="String" Name="CompanyName"></asp:Parameter>

                <asp:Parameter Type="String" Name="ContactTitle"></asp:Parameter>

            </InsertParameters>

        </asp:SqlDataSource>

    </div>

    </form>

</body>

</html>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 五华县| 伊春市| 泰兴市| 灯塔市| 象山县| 广丰县| 沁阳市| 阆中市| 永州市| 高邮市| 丰顺县| 绥江县| 莱阳市| 黑水县| 错那县| 同德县| 甘孜县| 余江县| 朔州市| 清苑县| 麻栗坡县| 江门市| 定州市| 西安市| 邵阳市| 偃师市| 平陆县| 孝感市| 扎赉特旗| 武山县| 咸宁市| 深水埗区| 农安县| 汤阴县| 北票市| 兴义市| 深州市| 吴旗县| 韩城市| 兴海县| 长乐市|