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("&l