六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

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

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<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="http://www.w3.org/1999/xhtml" >

<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>




主站蜘蛛池模板: 日韩综合在线视频 | 色国产视频 | 午夜久久久 | 日不卡在线| 青草青在线 | 青青色在线观看 | 婷婷六月丁| 色视频一区二区三区 | 午夜免费看视频 | 欧美综合图区亚欧综合图区 | 青青草原在线播放 | 伊人伊人影院 | 亚洲第一视频网站 | 婷婷激情久久 | 日韩黄色网址 | 午夜小视频在线播放 | 一级做性色a爰片久久毛片免费 | 伊人久久精品 | 青草福利视频 | 视频精品一区二区 | 色日韩在线 | 性调教视频 | 亚洲六月丁香婷婷综合 | 日本三级一区 | 青青草自拍 | 欧美特黄一区二区三区 | 中日韩欧美在线观看 | 人成午夜视频 | 日本高清视频在线免费观看 | 五月婷婷在线观看视频 | 日日精品| 日本在线精品视频 | 亚洲高清二区 | 天天色天天操综合网 | 桃花久久 | 在线观看亚洲欧美 | 伊人免费在线观看 | 日本高清无卡码一区二区久久 | 日韩中文字幕在线看 | 我看黄色一级片 | 日日干夜夜骑 |