DataGrid classic edit update Delete Code

Source: Internet
Author: User

Private void datagrid1_editcommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Datagrid1.edititemindex = (INT) E. Item. itemindex;
Bindgrid ();
}

Private void datagrid1_pageindexchanged (Object source, system. Web. UI. webcontrols. datagridpagechangedeventargs E)
{
Datagrid1.currentpageindex = E. newpageindex;
Bindgrid ();
}

Private void datagrid1_deletecommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Sqlcommand CM = new sqlcommand ("deleteemp", mysqlconn );
Cm. commandtype = commandtype. storedprocedure;
Cm. Parameters. Add (New sqlparameter ("@ empid", sqldbtype. Int, 4 ));
Cm. Parameters ["@ empid"]. value = maid [(INT) E. Item. itemindex];

Cm. Connection. open ();
Try
{
Cm. executenonquery ();
Label1.text = "deleted ";

}
Catch (sqlexception)
{
Label1.text = "failed to delete ";
Label1.style ["color"] = "red ";
}
Cm. Connection. Close ();
Bindgrid ();
}

Private void datagrid1_cancelcommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Datagrid1.edititemindex =-1;
Bindgrid ();
}

Private void datagrid1_updatecommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Sqlcommand CM = new sqlcommand ("updateemp", mysqlconn );
Cm. commandtype = commandtype. storedprocedure;

Cm. Parameters. Add (New sqlparameter ("@ email", sqldbtype. varchar, 50 ));
Cm. Parameters. Add (New sqlparameter ("@ Tell", sqldbtype. varchar, 50 ));
Cm. Parameters. Add (New sqlparameter ("@ JB", sqldbtype. Int, 4 ));
Cm. Parameters. Add (New sqlparameter ("@ emp_id", sqldbtype. Int, 4 ));
String colvalue = (textbox) E. Item. cells [4]. controls [0]). text;
Cm. Parameters ["@ email"]. value = colvalue;

Colvalue = (textbox) E. Item. cells [5]. controls [0]). text;
Cm. Parameters ["@ JB"]. value = colvalue;
Colvalue = (textbox) E. Item. cells [6]. controls [0]). text;
Cm. Parameters ["@ Tell"]. value = colvalue;

Cm. Parameters ["@ emp_id"]. value = maid [(INT) E. Item. itemindex];
Cm. Connection. open ();
Try
{
Cm. executenonquery ();
Label1.text = "edited ";
Datagrid1.edititemindex =-1;
}
Catch (sqlexception)
{
Label1.text = "Edit failed ";
Label1.style ["color"] = "red ";
}
Cm. Connection. Close ();
Bindgrid ();
}

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.