Edit the DataGrid and delete the primary code for backup.

Source: Internet
Author: User

# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Maid + = new System. Web. UI. WebControls. Maid pageindexchanged );
This. DataGrid1.SortCommand + = new System. Web. UI. WebControls. DataGridSortCommandEventHandler (this. DataGrid1_SortCommand );
This. Maid + = new System. Web. UI. WebControls. Maid (this. Maid deletecommand );
This. Maid + = new System. Web. UI. WebControls. Maid (this. Maid editcommand );
This. Maid + = new System. Web. UI. WebControls. Fig cancelcommand );
This. Maid + = new System. Web. UI. WebControls. Maid (this. Maid updatecommand );
}
# Endregion

Private void DataGrid1_DeleteCommand (object source, System. Web. UI. WebControls. DataGridCommandEventArgs e)
{
If (maid. Count = 1)
{
If (maid! = 0)
{
DataGrid1.CurrentPageIndex = maid-1;
}
}
Us. Userid = int. Parse (e. Item. Cells [0]. Text );
Us. users_del ();
Bind ();
}

Private void DataGrid1_SortCommand (object source, System. Web. UI. WebControls. DataGridSortCommandEventArgs e)
{
String str = e. SortExpression;
If (ViewState ["sort"]. ToString () = str + "desc ")
{
ViewState ["sort"] = str + "asc ";
}
Else
{
ViewState ["sort"] = str + "desc ";
}
Bind ();
}

Protected void button#click (object sender, System. EventArgs e)
{
String str = TextBox1.Text;
ViewState ["chazao"] = "useradmin like '%" + str + "% '";
Bind ();

}

Private void DataGrid1_PageIndexChanged (object source, System. Web. UI. WebControls. DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e. NewPageIndex;
Bind ();
}
Protected void DataGrid1_EditCommand (object source, DataGridCommandEventArgs e)
{
DataSet ds = us. users_sel ();
DataView dv = ds. Tables [0]. DefaultView;
DataGrid1.EditItemIndex = e. Item. ItemIndex;
DataGrid1.DataSource = dv;
DataGrid1.DataBind ();
}
Protected void maid cancelcommand (object source, maid e)
{
DataSet ds = us. users_sel ();
DataView dv = ds. Tables [0]. DefaultView;
DataGrid1.EditItemIndex =-1;
DataGrid1.DataSource = dv;
DataGrid1.DataBind ();
}
Protected void DataGrid1_UpdateCommand (object source, DataGridCommandEventArgs e)
{
String useradmin = (TextBox) e. Item. Cells [1]. Controls [0]). Text;
String username = (TextBox) e. Item. Cells [2]. Controls [0]). Text;
String email = (TextBox) e. Item. Cells [3]. Controls [0]). Text;

SqlConnection connUpdate = new SqlConnection (ConfigurationManager. receivettings ["connstr"]);
ConnUpdate. Open ();
String SQL _edit = "UPDATE users" + "SET useradmin = '" + useradmin + "'," + "username = '" + username + "', "+" useremail = '"+ email +" 'where userid = "+ e. item. cells [0]. text;
SqlCommand sqlCommandUpdate = new SqlCommand (SQL _edit, connUpdate );
SqlCommandUpdate. ExecuteNonQuery ();
ConnUpdate. Close ();
DataSet ds = us. users_sel ();
DataView dv = ds. Tables [0]. DefaultView;
DataGrid1.EditItemIndex =-1;
DataGrid1.DataSource = dv;
DataGrid1.DataBind ();
}

From snail bait

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.