Tip Note: Integration of DataGrid events

Source: Internet
Author: User
Tags dname
I believe that everyone will use the DataGrid on the website background management page to edit data, such as deleting, editing, updating, and clicking data. Do you want to click several times to generate related event functions? For example, generate: Private   Void Rssdatagrid_cancelcommand ( Object Source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Rssdatagrid. edititemindex =   - 1 ;
Bindthegrid ();
}

Private   Void Rssdatagrid_deletecommand ( Object Source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Datarow Dr = DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )];
Dr. Delete ();
Bindthegrid ();
}

Private VoidRssdatagrid_editcommand (ObjectSource, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Rssdatagrid. edititemindex=E. Item. itemindex;
Bindthegrid ();
}

Private   Void Rssdatagrid_updatecommand ( Object Source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Dname " ]
= (Textbox) (E. Item. cells [ 1 ]. Controls [ 0 ]). Text;
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Durl " ]
= (Textbox) (E. Item. findcontrol ( " Urltextbox " ). Text;
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Description " ]
= (Textbox) (E. Item. findcontrol ( " Descriptiontxt " ). Text;
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Dclass " ]
= (Dropdownlist) E. Item. findcontrol ( " Classdropdownlist " ). Selectedvalue;
Rssdatagrid. edititemindex =   - 1 ;
Bindthegrid ();
}

If this is not a problem, use it directly:

Private   Void Rssdatagrid_itemcommand ( Object Source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
Switch (E. commandname)
{
Case   " Edit " :
Rssdatagrid. edititemindex = E. Item. itemindex;
Bindthegrid ();
Break ;
Case   " Update " :
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Dname " ]
= (Textbox) (E. Item. cells [ 1 ]. Controls [ 0 ]). Text;
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Durl " ]
= (Textbox) (E. Item. findcontrol ( " Urltextbox " ). Text;
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Description " ]
= (Textbox) (E. Item. findcontrol ( " Descriptiontxt " ). Text;
DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )] [ " Dclass " ]
= (Dropdownlist) E. Item. findcontrol ( " Classdropdownlist " ). Selectedvalue;
Rssdatagrid. edititemindex =   - 1 ;
Bindthegrid ();
Break ;
Case   " Cancel " :
Rssdatagrid. edititemindex =   - 1 ;
Bindthegrid ();
Break ;
Case   " Delete " :
Datarow Dr = DT. Tables [ 0 ]. Rows [E. Item. itemindex + Rssdatagrid. pagesize * (Rssdatagrid. pagecount -   1 )];
Dr. Delete ();
Bindthegrid ();
Break ;
}
}

You can see that it is simpler and more direct?

of course, the following functions cannot use the itemcommand function. Why do you see it? The parameters are different. private void rssdatagrid_sortcommand ( Object source, system. web. UI. webcontrols. datagridsortcommandeventargs e)
{< br> DT. tables [ 0 ]. defaultview. sort = E. sortexpression;
bindthegrid ();
}

Private   Void Rssdatagrid_selectedindexchanged ( Object Sender, system. eventargs E)
{

}
Private   Void Rssdatagrid_pageindexchanged ( Object Source, system. Web. UI. webcontrols. datagridpagechangedeventargs E)
{
Rssdatagrid. currentpageindex = E. newpageindex;
Bindthegrid ();
}


These things cannot be a trick, just a few tricks :)))

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.