Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding Data using DataGrid
Message
 
To
08/10/2003 10:59:44
Ron Graham
Crystal Vision Software Ltd.
Toledo, Ohio, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00835567
Message ID:
00837450
Views:
22
Ron,

Again, my apologies for taking a few days to get back to you on this.

I checked out the article you referenced, and have outlined instructions below for adding the ability to create a new record in a DataGrid with MM .NET:

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);
}
else
{
	DataSet dsOrderDetail = (DataSet)Session["dsOrderDetail"];
	this.oOrderDetail.SetCurrentDataSet(dsOrderDetail);
}
Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform