人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開(kāi)發(fā)教程 > 詳細(xì)頁(yè)面

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

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

更新時(shí)間:2022-08-01 文章作者:未知 信息來(lái)源:網(wǎng)絡(luò) 閱讀次數(shù):

看了下國(guó)外某巨牛的BLOG,大概是講asp.net 2.0中用GRIDVIEW插入新記錄的,方法比較特別,但效果一般,故將程序轉(zhuǎn)之,較為簡(jiǎ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>

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 安徽省| 纳雍县| 闸北区| 济南市| 康马县| 苍南县| 田阳县| 广安市| 廉江市| 都昌县| 牙克石市| 玉门市| 黔东| 苍溪县| 南雄市| 交城县| 得荣县| 津南区| 徐闻县| 马关县| 绍兴县| 彭阳县| 锡林郭勒盟| 喀喇| 太仆寺旗| 始兴县| 樟树市| 梅州市| 普兰县| 哈巴河县| 克东县| 泰来县| 浑源县| 健康| 七台河市| 遵化市| 邓州市| 济阳县| 囊谦县| 威远县| 前郭尔|