asp.net 2.0中用GRIDVIEW插入新记录
来源:互联网 发布:linux源代码分析博客 编辑:程序博客网 时间:2024/04/29 07:20
<!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插入新记录
- asp.net 2.0中用GRIDVIEW插入新记录
- asp.net 2.0中用GRIDVIEW插入新记录
- asp.net 2.0中用GRIDVIEW插入新记录
- asp.net 2.0中用GRIDVIEW插入新记录
- asp.net 2.0中用GRIDVIEW插入新记录 (转)
- asp.net2.0中用GRIDVIEW插入新记录
- ASP.NET 2.0/3.5中直接操作Gridview控件插入新记录
- Scott Mitchell 的ASP.NET 2.0数据教程之53:从GridView的页脚插入新记录
- Scott Mitchell 的ASP.NET 2.0数据教程之53:从GridView的页脚插入新记录 .
- 使用Gridview插入新记录
- ASP.NET 2.0中用Gridview控件操作数据
- ]在GridView中插入新记录
- [翻译]在GridView中插入新记录
- asp.net 2.0中一次性更新所有GRIDVIEW的记录
- asp.net 2.0中一次性更新所有GRIDVIEW的记录
- asp.net 2.0中一次性更新所有GRIDVIEW的记录
- asp.net 2.0中一次性更新所有GRIDVIEW的记录
- C语言实现树结构
- 7步实现GridView控件ajax化
- 他们说java web 没前途
- asp.net 2.0的gridview基本知识
- java面试常见32问
- asp.net 2.0中用GRIDVIEW插入新记录
- asp.net中的联动菜单
- ASP.NET 打开新窗口几种方法
- Excel技术资源网站演义
- ASP.NET中Gridview控件高级技巧详细分析
- ASP.NET2.0中Gridview中数据操作技巧
- ASP.NET2.0中Gridview中的内容导出到Excel
- 目标定了,就坚持的走下去
- 他的程序人生