Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Add rows from grid and otherwise (Web) -- urgent
Message
From
11/10/2004 00:46:57
 
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00896357
Message ID:
00950322
Views:
23
Kevin, I know these old articles probably haunt you forever (especially around Holloween), but they sure help. I've been trying to add this "New" button to the Web OrderDetails exercise, but I can't get it to work. For one, it seems your call to NewRow in your example doesn't match any of the MM overrides. So I tried it with a DefaultValues object as the last parameter, in which I set the OrderID. Now, the new row is getting created, but all the values are null. The DefaultValues object is ok (used your example). Here's my code that adds the new row: This doesn't generate an error, but the new row doesn't get the OrderID value I passed.
		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,
				new OrderDetailDefaultValues(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);
		}
Thanks for any help. BTW, I could not find the instructions for adding a new row to an in-line editing grid in the latest Dev Guide. It would be great to have that.


>>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);
>}
>else
>{
>	DataSet dsOrderDetail = (DataSet)Session["dsOrderDetail"];
>	this.oOrderDetail.SetCurrentDataSet(dsOrderDetail);
>}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform