Asp.net| inserted to see a foreign giant cow blog, probably speaking asp.net 2.0 with the GridView Insert new records, the method is more special, but the effect
Generally, so the program to turn, simpler, do not explain and so on.
<%@ 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>
<title>untitled page</title>
<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= "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"/>