添加删除、更新按钮的提示确认信息 以及DATAGRID的添加、插入、更新、删除操作,添加删除、更新按钮的提示确认信息,以及DATAGRID的添加、插入、更新、删除操作。
【 tulaoshi.com - ASP.NET 】
代码using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace DataGridDemoCS{ /// /// MSDNDemo1 的摘要说明。 /// public class MSDNDemo1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; protected System.Data.SqlClient.SqlCommand sqlSelectCommand1; protected System.Data.SqlClient.SqlCommand sqlInsertCommand1; protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1; protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1; protected DataGridDemoCS.dsCustomers dsCustomers1; protected System.Data.SqlClient.SqlConnection sqlConnection1; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { bindData(); } } void bindData() { sqlDataAdapter1.Fill(dsCustomers1); DataGrid1.DataBind(); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(); this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); this.dsCustomers1 = new DataGridDemoCS.dsCustomers(); ((System.ComponentModel.ISupportInitialize)(this.dsCustomers1)).BeginInit(); this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand); this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand); this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand); this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand); this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound); // // sqlDataAdapter1 // this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1; this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1; this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1; this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), new System.Data.Common.DataColumnMapping("ContactName", "ContactName"), new System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"), new System.Data.Common.DataColumnMapping("Address", "Address"), new System.Data.Common.DataColumnMapping("City", "City"), new System.Data.Common.DataColumnMapping("Region", "Region"), new System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"), new System.Data.Common.DataColumnMapping("Country", "Country"), new System.Data.Common.DataColumnMapping("Phone", "Phone"), new System.Data.Common.DataColumnMapping("Fax", "Fax")})}); this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1; // // sqlDeleteCommand1 // this.sqlDeleteCommand1.CommandText = @"DELETE FROM Customers WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Addr来源:http://www.tulaoshi.com/n/20160129/1487436.html
看过《添加删除、更新按钮的提示确认信息 以及DATAGRID的添加、插入、更新、删除操作》的人还看了以下文章 更多>>