<% @ Page language = "c #" debug = "true"%>
<% @ Import namespace = "system.data"%>
<% @ Import namespace = "system.data.sqlclient"%>
// make first SQL
String SQL = "";
String strcn = "data source = .; initial catalog = aa; user ID = sa; password =;"
// Create a DataSource Function
Public iCollection createDataSource () {
SqlConnection Conn = New SqlConnection (STRCNN);
SqlDataAdapter DB_SQLADAPTOR = New SqlDataAdapter (SQL, CONN);
DataSet DS = New DataSet ();
DB_SQLADAPTOR.FILL (DS, "MyDatareSult");
DataView myview = ds.tables ["mydataresis]. Defaultview;
Return myView;
}
// Do Page Load
Public void Page_load (Object Sender, Eventargs E) {
STRCNN = "Data Source = .; initial catalog = aa; user ID = sa; password =;";
IF (! ispostback)
{
SQL = "SELECT * from people";
People.DataSource = CREATEDASOURCE ();
People.DATABIND ();
}
}
Public void Page_Grid (Object Sender, DataGridPageChangeDeventArgs E)
{
SQL = "SELECT * from people";
// set currentpageindex to the page the user click.
People.currentPageIndex = E.NewpageIndex;
// rebind the data.
People.DataSource = CREATEDASOURCE ();
People.DATABIND ();
}
Public void people_edit (Object Sender, DataGridCommandeventArgs E)
{
SQL = "SELECT * from people";
People.EDititeMindex = E.Item.itemindex;
People.DataSource = CREATEDASOURCE ();
People.DATABIND ();
}
Public void people_cancel (Object Sender, DataGridCommandeventArgs E)
{
SQL = "SELECT * from people";
People.editItemIndex = -1;
People.DataSource = createDataSource (); people.databind ();
}
Public Void People_Update (Object Sender, DataGridCommandeventArgs E)
{
String firstname = ((TextBox) E.Item.cells [1] .controls [1]).
String lastname = ((TextBox) E.Item.cells [2] .controls [1]).
SqlConnection ConnUpdate = New SqlConnection (STRCNN);
Connupdate.open ();
String SQL_EDIT = "Update People"
"Set firstname = '" firstname.replace ("'", "'') " " "
"Lastname = '" lastname.replace ("'", "'') " '"
"Where pkid =" E.Item.cells [0] .TEXT;
Sqlcommand sqlcommandupdate = new sqlcommand (SQL_EDIT, ConnUpdate);
Sqlcommandupdate.executenonQuery ();
Connupdate.close ();
SQL = "SELECT * from people";
People.editItemIndex = -1;
People.DataSource = CREATEDASOURCE ();
People.DATABIND ();
}
Public void people_delete (Object Sender, DataGridCommandeventArgs E) {
SqlConnection connDel = new SqlConnection (STRCNN);
CONNDEL.OPEN ();
String SQL_DEL = "delete from people"
"Where pkid =" E.Item.cells [0] .TEXT;
Sqlcommand sqlcommanddel = new sqlcommand (sql_del, conndel);
Sqlcommanddel.executenonQuery ();
ConNDEL.CLOSE ();
SQL = "SELECT * from people";
People.editItemIndex = -1;
People.DataSource = CREATEDASOURCE ();
People.DATABIND ();
}
script>
edit people b>
font>