服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

datagrid web control 基本操作


  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);
  
  }*/

扫描关注微信公众号