DataGrid Web Control Basic Operation

xiaoxiao2021-03-06  16

DGCategory is a DataGrid for displaying the category table

Automatic Page: AllowPaging = true !!!!

Private void DGCategory_pageIndexchanged (Object Source, System.Web.ui.WebControls.DataGridPageChangeDeventargs E)

{

DGCategory.currentPageIndex = E.NEWPAGEINDEX;

DGCategory.DATABIND ();

}

Sort: Default Press "PKID" Sort

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 (); // underlying data interface

CategoryData categoryset = productsys.getcategories (1); // underlying data interface, return ID to 1 Category

DataView categoryview = categoryset.tables [categoryData.categories_table] .defaultview;

CategoryView.sort = Sortorder;

Lbltitle.Text = "Press" Sortorder "Sort";

DGCategory.DataSource = CategoryView;

DGCategory.DATABIND ();

}

Private Void Page_Load (Object Sender, System.EventArgs E)

{

Binddata ("pkid");

}

Edit, update, cancel:

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 strune = "";

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); / / Need to provide updated interfaces in the background

DGCategory.editItemIndex = -1;

}

Catch

{

Response.write ("