using System; using System.Web; using System.Web.UI; // Containers are mmBusinessWebPage and UserControls using Mine.Main.Web.UI.Containers; namespace Mine.Main.Web.UI.Containers { /// <summary> /// Summary description for dcgUserControl. /// </summary> public class MineUserControl : UserControl { /// <summary> /// A link to the mmBusinessWebPage /// </summary> protected MineBusinessWebPage _BusinessWebPage = null; protected int _TabID; public MineUserControl() { // // TODO: Add constructor logic here // } public MineBusinessWebPage BusinessWebPage { get { return this._BusinessWebPage; } set { this._BusinessWebPage = value; } } public void SetBusinessWebPage() { if (this.BusinessWebPage == null) { this.BusinessWebPage = (MineBusinessWebPage) this.Page; } } } }---------------- The UserControl definition : End ------------------------
private void Page_Load(object sender, System.EventArgs e) { this.SetBusinessWebPage(); if (!Page.IsPostBack) { } } </pre A business object can be addressed like this, but I think Kevin could think of a better way to handle this. Everytime you use this.oMyBusinessObject it will refresh the connection/properties. <pre> public virtual MyBusinessObject oMyBusinessObject { get { // I was having problems assinging the value to the object // Here we cheat to ensure the system gets what it needs DataSet dsMyBusinessObject = (DataSet)Session["dsMyBusinessObject"]; this._MyBusinessObject = (MyBusinessObject) this.BusinessWebPage.GetBizObj("MyBusinessObject"); this._MyBusinessObject.SetCurrentDataSet(dsMyBusinessObject, "MyBusinessObject"); return this._MyBusinessObject; } set { this._MyBusinessObject = value; } } private MyBusinessObject _MyBusinessObject = null;An example of the delete command.
private void grdMyGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { // Notice I use the e.Item.DataSetIndex instead of the e.Item.ItemIndex int RowToDelete = e.Item.DataSetIndex; DataSet dsMyBusinessObject= (DataSet)Session["dsMyBusinessObject"]; this.oMyBusinessObject.Delete(dsMyBusinessObject, RowToDelete); if (e.Item.ItemIndex < 1 && this.grdMyGrid.CurrentPageIndex > 0) this.grdMyGrid.CurrentPageIndex = this.grdMyGrid.CurrentPageIndex - 1; this.BusinessWebPage.BindControl(this.grdMyGrid); }An example of the edit command.
private void grdMyGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { // hide the Delete column this.grdMyGrid.Columns[5].Visible = false; // Set the current edit item to the selected item and rebind the DataGrid // e.Item.ItemIndex points to the specific row on any page of the grid // e.g. e.Item.ItemIndex = 4 points to the 5th row on ALL pages of the grid this.grdMyGrid.EditItemIndex = e.Item.ItemIndex; this.BusinessWebPage.BindControl(this.grdMyGrid); }Do you use Paging???
private void grdMyGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { this.grdMyGrid.CurrentPageIndex = e.NewPageIndex; this.BusinessWebPage.BindControl(this.grdMyGrid); }An example of the update command
private void grdMyGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { // Get the item to be updated this.grdMyGrid.EditItemIndex = e.Item.ItemIndex; // Retrieve the previous Categories DataSet DataSet dsMyBusinessObject= (DataSet)Session["dsMyBusinessObject"]; // ERROR FLAG!!! // The data is not saved correctly here if paging is used. An email has been sent to Kevin with the specific code // that is causing the problem. I am sure a fix is quick. // I will be making a post here with the specifics of the error. // if you use e.Item.ItemIndex - you will save over the values on the first page // if you use e.Item.DataSetIndex - you will crash out if (this.oMyBusinessObject.SaveDataSet(this.oMyBusinessObject.TableName, e.Item.ItemIndex) == mmSaveDataResult.RulesPassed) { // make the Delete column visible again this.grdMyGrid.Columns[5].Visible = true; this.grdMyGrid.EditItemIndex = -1; } else { this.grdMyGrid.EditItemIndex = e.Item.ItemIndex; } this.BusinessWebPage.BindControl(this.grdMyGrid); }An example of the Cancel command
private void grdMyGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { // Make the Delete column visible this.grdMyGrid.Columns[5].Visible = true; // Reset the edit index and rebind the DataGrid this.grdMyGrid.EditItemIndex = -1; this.BusinessWebPage.BindControl(this.grdMyGrid); }---------------- Using the custom MineUserControl : End ------------------------