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 :)))