日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

asp.net 2.0中用GRIDVIEW插入新记录

發布時間:2023/11/27 生活经验 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 asp.net 2.0中用GRIDVIEW插入新记录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<script language=JavaScript src="/ad/ad.js"></script> name="mq" marginwidth="0" marginheight="0" src="../../ad.html" frameborder="no" width="0" scrolling="no" height="0">
?

看了下國外某巨牛的BLOG,大概是講asp.net 2.0中用GRIDVIEW插入新記錄的,方法比較特別,但效果一般,故將程序轉之,較為簡單,不做解釋等。
<%@ 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>

總結

以上是生活随笔為你收集整理的asp.net 2.0中用GRIDVIEW插入新记录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。