Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dropdownlist in mmDataGrid
Message
 
To
01/05/2006 12:26:19
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01118076
Message ID:
01118906
Views:
7
There's a better way, IMO, than what you said you're looking for. I have created several custom column based on the work at Metabuilders.com. Which makes for much better reuse than the template column solution.

Are you using .Net 1.1 or 2.0? This was what I did in 1.1 and haven't tried to get it working in 2.0 or the latest MM.Net but it should be a enough to get you started. Also I assume you're using the DataGrid not the new GridView.

First go to Metabuilders.com and download his BoundLookupColumn control and add it to your project.

In the aspx page inside your DataGrid tags you'll put something in like this
<cc1:BoundLookupColumn HeaderText="Location" SortExpression="Location" DataField="LocationID"></cc1:BoundLookupColumn>
In the aspx.cs file you'll have to put some code to load the columns source list like this
BoundLookupColumn blc = BoundLookupColumn.FindColumn(this.grdTeams);
blc.LookupDataSource = // some object that implements IListSource or IEnumberabl - I always used a DataTable
blc.LookupDataValueField = "LocationID";
blc.LookupDataTextField = "LocationName";
Then create a subclass of the mm DataGrid if you haven't already. Then you just need to override at least one of the BindBack methods. Here's how I did it
public override void BindBack(DataSet ds, string tableName)
{
	if (this.EditItemIndex >= 0)
	{
		DataGridItem item = this.Items[this.EditItemIndex];
		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];
			
				...
				else if (column is BoundLookupColumn)
				{
					BoundLookupColumn BoundCol = (BoundLookupColumn)column;
					if (!BoundCol.ReadOnly)
					{
						if (BoundCol.DataField.Length > 0)
						{
							DropDownList ddl = (DropDownList)cell.Controls[0];
							ds.Tables[tableName].Rows[EditItemIndex][BoundCol.DataField] = ddl.SelectedValue;
						}
					}
				}
				...
			}
			CellNumber++;
		}
	}
}
Rip Ryness
International Falls, MN
Previous
Reply
Map
View

Click here to load this message in the networking platform