0% found this document useful (0 votes)
173 views2 pages

Gridxview

The document defines a class that handles loading and manipulating data in a dataset across multiple ASPxGridView controls on a web page. The class loads data into two tables of a dataset from the session on page load. It then sets the data source of the first grid view and adds event handlers for row operations that manipulate the dataset in session.

Uploaded by

4321abc1234
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views2 pages

Gridxview

The document defines a class that handles loading and manipulating data in a dataset across multiple ASPxGridView controls on a web page. The class loads data into two tables of a dataset from the session on page load. It then sets the data source of the first grid view and adds event handlers for row operations that manipulate the dataset in session.

Uploaded by

4321abc1234
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using using using using using using using using using using using using

System; System.Data; System.Configuration; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Web.UI.HtmlControls; DevExpress.Web.ASPxGridView; System.Collections; DevExpress.Web.ASPxEditors;

public partial class _Default : System.Web.UI.Page { DataSet ds = null; protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack && !IsCallback) { ds = new DataSet(); DataTable masterTable = new DataTable(); masterTable.Columns.Add("ID", typeof(int)); masterTable.Columns.Add("Data", typeof(string)); masterTable.PrimaryKey = new DataColumn[] { masterTable.Columns["ID" ] }; DataTable detailTable = new DataTable(); detailTable.Columns.Add("ID", typeof(int)); detailTable.Columns.Add("MasterID", typeof(int)); detailTable.Columns.Add("Data", typeof(string)); detailTable.PrimaryKey = new DataColumn[] { detailTable.Columns["ID" ] }; int index = 0; for(int i = 0;i < 20;i++) { masterTable.Rows.Add(new object[] { i, "Master Row " + i.ToStrin g() }); for(int j = 0;j < 5;j++) detailTable.Rows.Add(new object[] { index++, i, "Detail Row " + j.ToString() }); } ds.Tables.AddRange(new DataTable[] { masterTable, detailTable }); Session["DataSet"] = ds; } else ds = (DataSet)Session["DataSet"]; ASPxGridView1.DataSource = ds.Tables[0]; ASPxGridView1.DataBind(); } protected void ASPxGridView2_BeforePerformDataSelect(object sender, EventArg s e) { ds = (DataSet)Session["DataSet"]; DataTable detailTable = ds.Tables[1]; DataView dv = new DataView(detailTable); ASPxGridView detailGridView = (ASPxGridView)sender; dv.RowFilter = "MasterID = " + detailGridView.GetMasterRowKeyValue().ToS tring(); detailGridView.DataSource = dv; } protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.

ASPxDataUpdatingEventArgs e) { ds = (DataSet)Session["DataSet"]; ASPxGridView gridView = (ASPxGridView)sender; DataTable dataTable = gridView.SettingsDetail.IsDetailGrid ? ds.Tables[1 ] : ds.Tables[0]; DataRow row = dataTable.Rows.Find(e.Keys[0]); IDictionaryEnumerator enumerator = e.NewValues.GetEnumerator(); enumerator.Reset(); while(enumerator.MoveNext()) row[enumerator.Key.ToString()] = enumerator.Value; gridView.CancelEdit(); e.Cancel = true; } protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data .ASPxDataInsertingEventArgs e) { ds = (DataSet)Session["DataSet"]; ASPxGridView gridView = (ASPxGridView)sender; DataTable dataTable = gridView.SettingsDetail.IsDetailGrid ? ds.Tables[1 ] : ds.Tables[0]; DataRow row = dataTable.NewRow(); e.NewValues["ID"] = dataTable.Rows.Count; IDictionaryEnumerator enumerator = e.NewValues.GetEnumerator(); enumerator.Reset(); while(enumerator.MoveNext()) if(enumerator.Key.ToString() != "Count") row[enumerator.Key.ToString()] = enumerator.Value; gridView.CancelEdit(); e.Cancel = true; dataTable.Rows.Add(row); } protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data. ASPxDataDeletingEventArgs e) { int i = ASPxGridView1.FindVisibleIndexByKeyValue(e.Keys[ASPxGridView1.Ke yFieldName]); Control c = ASPxGridView1.FindDetailRowTemplateControl(i, "ASPxGridView2 "); e.Cancel = true; ds = (DataSet)Session["DataSet"]; ds.Tables[0].Rows.Remove(ds.Tables[0].Rows.Find(e.Keys[ASPxGridView1.Key FieldName])); } }

You might also like