注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 CCIE-Lab考试将新增10分钟..
 帮助

DataGrid基础应用


2006-03-30 09:37:00
 标签: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);
              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);
         }*/
 




    文章评论
 
 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: