Example of editing and deleting a gridview

Source: Internet
Author: User
Aspx: <asp: gridview id = "mygvclass" runat = "server" autogeneratecolumns = "false" width = "100%" datakeynames = "ID" onrowcancelingedit = "inline" onrowediting = "inline" onrowupdating = "mygvclass_rowupdating "onrowdeleting =" mygvclass_rowdeleting "bordercolor =" # cccccc "borderstyle =" solid "borderwidth =" 1px ">
<Columns>
<Asp: boundfield datafield = "ID" headertext = "no." readonly = "true">
<Itemstyle horizontalalign = "center"/>
<Headerstyle horizontalalign = "center" width = "10%"/> </ASP: boundfield>
<Asp: boundfield datafield = "classname" headertext = "topic name">
<Itemstyle horizontalalign = "Left"/>
<Headerstyle horizontalalign = "Left" width = "52%" type = "codeph" text = "codeph"/>
<Controlstyle width = "80%" type = "codeph" text = "/codeph"/>
</ASP: boundfield>
<Asp: boundfield datafield = "stime" headertext = "Operation Time" readonly = "true">
<Itemstyle horizontalalign = "center"/>
<Headerstyle horizontalalign = "center" width = "20%"/> </ASP: boundfield>
<Asp: commandfield headertext = "operation" showeditbutton = "true">
<Headerstyle horizontalalign = "center" width = "12%"/>
<Itemstyle horizontalalign = "center"/> </ASP: commandfield>
<Asp: templatefield headertext = "delete" showheader = "false">
<Itemstyle horizontalalign = "center"/>
<Headerstyle horizontalalign = "center" width = "6%"/>
<Itemtemplate>
<Asp: linkbutton id = "linkbutton1" onclientclick = "Return confirm ('Are you sure you want to delete this record? '); "Runat =" server "causesvalidation =" false "commandname =" delete"
TEXT = "delete"> </ASP: linkbutton>
</Itemtemplate>
</ASP: templatefield>
</Columns>
<Headerstyle backcolor = "lightgray"/>
</ASP: gridview>

CS: protected void mygvclass_rowediting (Object sender, gridviewediteventargs E)
{
Mygvclass. editindex = E. neweditindex;
This. mygvclass. editrowstyle. backcolor = color. aliceblue;
Bindata ();
}
Protected void mygvclass_rowcancelingedit (Object sender, gridviewcancelediteventargs E)
{
Mygvclass. editindex =-1;
Bindata ();
}
Protected void mygvclass_rowupdating (Object sender, gridviewupdateeventargs E)
{
String Strid = This. mygvclass. datakeys [E. rowindex]. value. tostring ();
String strclassname = (textbox) (mygvclass. Rows [E. rowindex]. cells [1]. controls [0]). Text. Trim (). tostring ();

Webclass. articlelist TMP = new webclass. articlelist ();
TMP. editclass (strclassname, Strid );

Mygvclass. editindex =-1;
Bindata ();
}
Protected void mygvclass_rowdeleting (Object sender, gridviewdeleteeventargs E)
{
String Strid = This. mygvclass. datakeys [E. rowindex]. value. tostring ();

Webclass. articlelist TMP = new webclass. articlelist ();
TMP. delclass (Strid );

Mygvclass. editindex =-1;
Bindata ();
}

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.