Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug Report - mmDataGrid
Message
From
20/10/2004 12:39:58
 
 
To
19/10/2004 20:25:13
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00952859
Message ID:
00953052
Views:
15
Two pieces of code will fix the problem...


Within a derived version of the mmDataGrid add the following code. Use the derived object on your web pages. This will save the data to the correct record. After fixing this, a new problem occurred. The error rules were bypassed. The correction for that is listed below.
/// <summary>
/// Stores the current values in the DataGrid back into the
/// specified DataSet and table
/// </summary>
/// <param name="ds">DataSet</param>
/// <param name="tableName">Table Name</param>
public override void BindBack(DataSet ds, string tableName)
{
	if (this.EditItemIndex >= 0)
	{
		DataGridItem item = this.Items[this.EditItemIndex];
		int CellNumber = 0;
		int DataIndex = item.DataSetIndex;

		foreach(TableCell cell in item.Cells)
		{
			// Need to check HasControls because if a column is set to ReadOnly,
			// HasControls() returns false. Trying to process the controls collection
			// when HasControls() is false, throws an exception.
			if (cell.HasControls())
			{
				DataGridColumn column = this.Columns[CellNumber];
				if (column is BoundColumn)
				{
					BoundColumn BoundCol = (BoundColumn)column;
					if (cell.Controls[0] is TextBox)
					{
						TextBox txtBox = (TextBox)cell.Controls[0];
						ds.Tables[tableName].Rows[DataIndex][BoundCol.DataField] = txtBox.Text;
					}
				}
			}
			CellNumber++;
		}
	}
}
Within your new BusinessObject.cs e.g. ABusinessObject before your final data BusinessObjects. Kevin will probably improve on this, but this does work for now. This method receives two int values to differenciate it from the mm version of SaveDataSet. In this case the correct datarow is assigned to the "this.DataRow". Error icons will now appear as usual; though I am missing the error message at the bottom/top of my page.
/// <summary>
/// (10) Saves the current DataSet's specified table to the default database
/// </summary>
/// <param name="tableName">Table Name</param>
/// <returns>mmSaveDataResult enum value</returns>
/// <param name="currentGridRow">Current Grid Row</param>
/// <param name="currentDataRow">Current Data Row</param>
public virtual mmSaveDataResult SaveDataSet(string tableName, int currentGridRow, int currentDataRow)
{
	// Save the specified row number
	this.RowNum = currentDataRow;
	// Get the corresponding data row
	DataSet ds = this.GetCurrentDataSet();
	this.DataRow = ds.Tables[tableName].Rows[currentDataRow];
	// Save the data
	mmSaveDataResult result = this.SaveDataSet(ds, tableName);
	// Reset the row number to zero
	this.RowNum = 0;
	// Return the result
	return result;
}
>Hello Kevin,
>
>Could you please supply me with a correction install?
>
>The example:
>
>DataGrid using Paging, Edit, Cancel and Delete.
>
>Assume Paging = 7 rows per page
>Assume dataset is larger than 7
>Assume this.EditItemIndex has been assigned with e.Item.ItemIndex
>Assume you are on the second page.
>Assume you are on the 4th displayed record (e.Item.ItemIndex = 3, e.Item.DataSetIndex = 10)
>
>Point A - This is a good line pointing to the correct row in the DataGrid
>Point B - This is the bad line pointing to the 4th record in the table instead of the 11th.
>
>The pointer to the table must be adjusted for the specific page where the data is being editted.
>
>If I send DataSetIndex into the save instead of ItemIndex, the system will blow up at Point A
>
>
>The effected function (method, event, whatever...)
>
>
>public virtual void BindBack(DataSet ds, string tableName)
>{
>	if (this.EditItemIndex >= 0)
>	{
>		DataGridItem item = this.Items[this.EditItemIndex]; <----- A
>		int CellNumber = 0;
>
>		foreach(TableCell cell in item.Cells)
>		{
>			// Need to check HasControls because if a column is set to ReadOnly,
>			// HasControls() returns false. Trying to process the controls collection
>			// when HasControls() is false, throws an exception.
>			if (cell.HasControls())
>			{
>				DataGridColumn column = this.Columns[CellNumber];
>				if (column is BoundColumn)
>				{
>					BoundColumn BoundCol = (BoundColumn)column;
>					if (cell.Controls[0] is TextBox)
>					{
>						TextBox txtBox = (TextBox)cell.Controls[0];
>						ds.Tables[tableName].Rows[EditItemIndex][BoundCol.DataField] = txtBox.Text; <---- B
>					}
>				}
>			}
>			CellNumber++;
>		}
>	}
>}
>
Gordon de Rouyan
DC&G Consulting
Edmonton, Alberta
Email: derouyag@shaw.ca
Previous
Reply
Map
View

Click here to load this message in the networking platform