欢迎光临
我们一直在努力

DataGrid Web Control 基本操作-.NET教程,数据库应用

建站超值云服务器,限时71元/月

dgcategory是用于显示类别表的datagrid

自动分页: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); //底层数据接口,返回id为1的category

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

}*/

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » DataGrid Web Control 基本操作-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章