分页:allowpaging= true!!!!
private void dgcategory_pageindexchanged(object source, system.web.ui.webcontrols.datagridpagechangedeventargs e)
{
dgcategory.currentpageindex=e.newpageindex;
dgcategory.databind();
}
排序:默认按“pkid”排序
private void dgcategory_sortcommand(object source, system.web.ui.webcontrols.datagridsortcommandeventargs e)
{
string sortorder=e.sortexpression.tostring();
binddata(sortorder);
}
private void binddata(string sortorder)
{
productsystem productsys=new productsystem();
categorydata categoryset=productsys.getcategories(1);
dataview categoryview=categoryset.tables[categorydata.categories_table].defaultview;
categoryview.sort=sortorder;
lbltitle.text=”按”+sortorder+”排序”;
dgcategory.datasource=categoryview;
dgcategory.databind();
}
private void page_load(object sender, system.eventargs e)
{
binddata(“pkid”);
}
编辑,更新,取消:
private void dgcategory_editcommand(object source, system.web.ui.webcontrols.datagridcommandeventargs e)
{
dgcategory.edititemindex=e.item.itemindex;
binddata(“pkid”);
}
private void dgcategory_cancelcommand(object source, system.web.ui.webcontrols.datagridcommandeventargs e)
{
dgcategory.edititemindex=-1;
binddata(“pkid”);
}
private void dgcategory_updatecommand(object source, system.web.ui.webcontrols.datagridcommandeventargs e)
{
string strupdate=””;
strupdate+=”pkid=”+((textbox)e.item.cells[1].controls[0]).text+””;
strupdate+=”parentid=”+((textbox)e.item.cells[2].controls[0]).text+””;
strupdate+=”description=”+((textbox)e.item.cells[3].controls[0]).text+””;
strupdate+=”isleaf=”+((textbox)e.item.cells[4].controls[0]).text+””;
try
{
cagegoryset.executeupdate(strupdate);//需要后台提供更新的接口
dgcategory.edititemindex=-1;
}
catch
{
response.write(“<script language=javascript>alert(未能完成更新,请…………)</script>”);
}
binddata(“pkid”);
}
private void dgcategory_deletecommand(object source, system.web.ui.webcontrols.datagridcommandeventargs e)
{
//获得关键字,使用datakeys集合访问数据列表控件中每个记录的键值(显示为一行)
//使得用户可以存储键字段而无需在控件中显示它
string pkid=dgcategory.datakeys[e.item.itemindex];
categoryset.executedelete(pkid);
}*/