Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
AddNew w/ inline editing datagrid?
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00855558
Message ID:
00855688
Vues:
16
Thanks a lot, Kevin. That's just what I needed. I probably had the sequence for the btnNew_Click event code at one point, but the Page_Load trick was the key.

Regards,
Chris.



>Chris,
>
>Here's some instructions that I'll be adding to the Dev Guide:
>
>1. Add a "New" button to your web form
>2. Add a "Click" event handler to the form for the New button
>3. Add code to the event handler that does the following:
>
>* Retrieve the DataGrid's DataSet from the Session object (or wherever you've persisted it)
>* Pass the DataSet to the associated business object's NewRow method
>* Store the DataSet back into the Session object
>* Set the DataGrid's ItemIndex property to the last row in the DataTable
>* Rebind the DataGrid
>
>Here's an example of what this code might look like:
>
>
>private void btnNew_Click(object sender, System.EventArgs e)
>{
>	// Retrieve the previous Order Detail DataSet
>	DataSet dsOrderDetail = (DataSet)Session["dsOrderDetail"];
>	// Add a new row to the DataSet
>	this.oOrderDetail.NewRow(dsOrderDetail, this.oOrderDetail.TableName, this.OrderID);
>	// Store the DataSet back into the session
>	Session["dsOrderDetail"] = dsOrderDetail;
>	// Set the new row for editing
>	this.grdOrderDetail.EditItemIndex = dsOrderDetail.Tables[oOrderDetail.TableName].Rows.Count-1;;
>	// Rebind the DataGrid
>	this.BindControl(this.grdOrderDetail);
>}
>
>
>There's one other thing you need to do to make this work properly.
>
>In your web form's Page_Load, if posting back, rather than retrieving the DataGrid data from the business object again, you should retrieve it from the Session variable (which contains the DataSet with the new row in it), and then you should call the business object's SetCurrentDataSet method so all of the binding occurs properly. For example:
>
>
>if (!IsPostBack)
>{
>	Session["dsOrderDetail"] = this.oOrderDetail.GetOrderDetail(OrderID);
>}
>else
>{
>	DataSet dsOrderDetail = (DataSet)Session["dsOrderDetail"];
>	this.oOrderDetail.SetCurrentDataSet(dsOrderDetail);
>}
>
>
>Regards,

chris jefferies
chris@freeranger.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform