using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 Database
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.RadioButton RadioButton1;
protected System.Web.UI.WebControls.RadioButton RadioButton2;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button btnProcess;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button btnAddNew;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label lblTitle;
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection odc = new SqlConnection("Data Source=TDS-JAREDPARKS;Database=Northwind;Integrated Security=SSPI;");
string sc;
sc = "SELECT CustomerID, ContactName FROM Customers";
SqlDataAdapter da = new SqlDataAdapter(sc, odc);
System.Data.DataSet ds = new DataSet();
da.Fill(ds, "Customers");
DataGrid1.DataSource = ds.Tables["Customers"];
DataGrid1.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string sc;
sc = "SELECT Customers.CustomerID, Customers.ContactName FROM Customers";
DataSet ds = new DataSet();
SqlConnection odc = new SqlConnection("Data Source=TDS-JAREDPARKS;Database=Northwind;Integrated Security=SSPI;");
SqlDataAdapter da = new SqlDataAdapter(sc, odc);
SqlCommandBuilder cb = new SqlCommandBuilder();
DataGrid1.DataSource = ds.Tables["Customers"];
//
string strCustomerID, strContactName;
string key = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
TextBox tb, tb2;
tb = (TextBox)(e.Item.Cells[1].Controls[0]);
strCustomerID = tb.Text;
tb2 = (TextBox)(e.Item.Cells[2].Controls[0]);
strContactName = tb.Text;
da.Update(ds, "Customers");
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
}
}