|
asp.net 2.0中用GRIDVIEW插入新记录 (1) 看了下国外某巨牛的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();
}
|