Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Add rows from grid and otherwise (Web) -- urgent
Message
 
À
20/04/2004 00:46:59
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00896357
Message ID:
00896660
Vues:
18
>What is the recommended way to add records from a form or a grid when you are creating a web application. THe jumpstarts don't talk about this at all, and I am having problems with Autoincrementing messing something up with my dataset updates. namely it overwrites data on the first record. Could someone give me a step by step procedure of what is the best way to do this?

Here are some instructions you'll find in the Dev Guide for the next release of MM .NET. They show how to add a new row to an in-place editing DataGrid:

Instructions for adding a New Row to an In-Place Editing DataGrid

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.
if (!IsPostBack)
{
	Session["dsOrderDetail"] = this.oOrderDetail.GetOrderDetail(OrderID);
}
Regards,

else
{
DataSet dsOrderDetail = (DataSet)Session["dsOrderDetail"];
this.oOrderDetail.SetCurrentDataSet(dsOrderDetail);
}
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform