protected void GridView_RowCreated(object sender, GridViewRowEventArgs e) { // if we have zero data rows (but a dummy row), hide the grid view row // and clear the controls off of that row so they don't cause binding errors if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex == 0 && LoadEmptyData) { e.Row.Visible = false; e.Row.Controls.Clear(); } //Following Logic records the correct row index of the //item that was selected for editing if ((dataKey != null) && (e.Row.RowType == DataControlRowType.DataRow) && !((e.Row.RowIndex == 0) && LoadEmptyData) && (this.DataKeys.Count > e.Row.RowIndex) && (this.DataKeys[e.Row.RowIndex][0] != null) && (this.DataKeys[e.Row.RowIndex][0].ToString() == dataKey.ToString())) { editIndexUsingDataKey = e.Row.RowIndex; } GetUpdatePanel.Update(); }
void TPMSFormView_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { StringBuilder errorMessage = new StringBuilder(); Exception ex = e.Exception; if (ex != null) { if (!(ex is ApplicationException)) { while (ex != null) { ; } ErrorLabel.Text = errorMessage.ToString(); } e.ExceptionHandled = true; e.KeepInEditMode = true; } else if (e.AffectedRows == 0) { e.KeepInEditMode = true; //Set Error Message only if no ErrorMessage was assigned by DataSource Control if (ErrorLabel.Text.Trim() == "") { ErrorLabel.Text = "Concurrency Error"; } } GetUpdatePanel.Update(); }
/// <summary> /// Called when insert/update/edit/cancel link buttons are clicked on GridView /// This method calls the insert method on ObjectDataSource and /// enables button control after insert operation is completed /// </summary> /// <param name="sender">Sender</param> /// <param name="e">GridView Command Event Arguments</param> protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e) { rowIndex = e.CommandSource is GridView ? -1 : ((GridViewRow)((Control)e.CommandSource).Parent.Parent).RowIndex; ObjectDataSource dataSource = (ObjectDataSource)this.Parent.FindControl(this.DataSourceID); if (dataSource != null) { if (e.CommandName == "Insert" && Page.IsValid) { try { //Following block of code is chekced for Exceptions //because Insert() will throw an exception if insert ito DB fails dataSource.Insert(); showButtons(); } catch (Exception ex) { //Object Data Source throws this exception on Primary Key, Unique Key and Foriegn Key Voilations //No Action is required here. //This exception ensures that gridview footer row is displayed and and typed in data is not lost. } } } GetUpdatePanel.Update(); }
void addButton_Click(object sender, EventArgs e) { hideButtons(); //Refreshing Grid content before changing to insert mode this.DataBind(); this.FooterRow.Visible = true; GetUpdatePanel.Update(); }
/// <summary> /// Called after user click edit control on page /// Disable add button when editing a row /// </summary> /// <param name="sender">Sender</param> /// <param name="e">GridView Edit Event Arguments</param> protected virtual void GridView_RowEditing(object sender, GridViewEditEventArgs e) { //Remembering the DataKey of the row that is being changed to edit mode //so that if the order of items in grid changes correct row can be identifed dataKey = this.DataKeys[e.NewEditIndex][0]; this.hideButtons(); GetUpdatePanel.Update(); }
/// <summary> /// Called when user select cancel button on editable row; /// reenable add button when done editing row /// </summary> /// <param name="sender">Sender</param> /// <param name="e">GridView Cancel Edit Event Arguments</param> protected void GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { this.showButtons(); if (this.ShowFooter == true) { this.ShowFooter = false; } GetUpdatePanel.Update(); }
/// <summary> /// Call after database has been updated, /// reenable add button when done editing row /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Grid View Updated Event</param> protected void GridView_RowUpdated(object sender, GridViewUpdatedEventArgs e) { if (e.AffectedRows == 0) { e.KeepInEditMode = true; } else { this.showButtons(); } GetUpdatePanel.Update(); }
void TPMSFormView_ItemInserted(object sender, FormViewInsertedEventArgs e) { StringBuilder errorMessage = new StringBuilder(); Exception ex = e.Exception; if (ex != null) { if (!(ex is ApplicationException)) { while (ex != null) { ; } ErrorLabel.Text = errorMessage.ToString(); } e.ExceptionHandled = true; e.KeepInInsertMode = true; } GetUpdatePanel.Update(); }
void TPMSGridView_PreRender(object sender, EventArgs e) { //Disable buttons if GridView is disabed if (!this.Enabled) { hideButtons(); } else { if ((dataKey != null) && (this.EditIndex != -1)) { this.EditIndex = editIndexUsingDataKey; } //Set Focus to footer row if it is visible if ((this.FooterRow != null) && (this.FooterRow.Visible == true)) { //If Ajax is used on page then following //line of code will properly set focus to footer row if (AjaxEnabledPage) { ScriptManager.GetCurrent(this.Page).SetFocus(FooterRow); } else { Page.SetFocus(FooterRow); } //Because Footer Row is visible gridview is in insert mode, so hiding AddButtons hideButtons(); // Put header below datacontrols in footer row; if (AddHeaderToFooter) { for (int i = 0; i < this.Columns.Count; i++) { string header = HeaderRow.Cells[i].Text; if (header != null && header != string.Empty && header != " ") { Label label = new Label(); label.Text = "<center>" + header + "</center>"; label.ID = "label00" + i.ToString(); label.BackColor = System.Drawing.Color.Black; label.ForeColor = System.Drawing.Color.White; label.Width = Unit.Percentage(100.0); label.Font.Bold = true; label.Font.Name = "verdana"; FooterRow.Cells[i].Controls.Add(label); } } } } else if (this.EditIndex > -1) { if (AjaxEnabledPage) { ScriptManager.GetCurrent(this.Page).SetFocus(this.Rows[this.EditIndex]); } else { Page.SetFocus(this.Rows[this.EditIndex]); } } else if ((this.rowIndex != -1) && (this.Rows.Count > 0)) { //Set Focus to the row that raised the post back event if ((this.rowIndex < this.Rows.Count) && ((this.Rows[this.rowIndex].RowState == DataControlRowState.Edit) || (this.rowIndex > 0))) { if (AjaxEnabledPage) { ScriptManager.GetCurrent(this.Page).SetFocus(this.Rows[this.rowIndex]); } else { Page.SetFocus(this.Rows[this.rowIndex]); } } } if (((this.FooterRow == null) || (this.FooterRow.Visible == false)) && (this.EditIndex < 0)) { showButtons(); } } GetUpdatePanel.Update(); }