Forum
 
 
Knowledge Base Forum
To post messages on the forum, you need to login first.
SearchForum Home
  Product Forums  smartDBforms.NET  Foreign Key Dro...
 Foreign Key Dropdown Sort
 
 2/20/2011 4:06:28 PM
Brett
6 posts


Foreign Key Dropdown Sort
Is there any way to dictate how the items in a FK dropdown get sorted? Right now, looks like they're just in the ordered stored in the DB, would like them to sort alphabetically. Thank (have I mentioned how much I love this tool?)
 2/23/2011 9:48:47 AM
Adillis Support
51 posts
adillis.com


Re: Foreign Key Dropdown Sort
Hi Brett,

Thank you very much.
Sorry for the delay, there were some issues finding the proper solution.
It is really a little bit tricky.

In order to sort the data in the FK dropdown you need to do the following.

  1. Register for the SmartDBControl  DataBinding event
  2. In the SmartDBControl.DataBinding  register for the dropdown DataBinding event
  3. In the dropdown.DataBinding sort the default data source and override the dropdown.DataSource property.
Here is example with the ctrlCategoryID SmartDBControl:
...
<smartDBforms:SmartDBControl Field="CategoryID" ID="ctrlCategoryID"
runat="server" ondatabinding="ctrlCategoryID_DataBinding" />
...

/////////////////////////////////
// DROPDOWN SORTING EXAMPLE
protected void ctrlCategoryID_DataBinding(object sender, EventArgs e)
{
DropDownList dropDownValue =
((SmartDBControl)sender).FindControl("DropDownValue") as DropDownList;
// Dropdown is availailable only in Edit mode. Check if exist.
if (dropDownValue != null)
// Register for the DataBinding event which will trigger just
//before the dropdown is filled with data
dropDownValue.DataBinding += new EventHandler(dropDownValue_DataBinding);

}

// This will fire after the standard databinding.
void dropDownValue_DataBinding(object sender, EventArgs e)
{
// Get the DropDown data table
System.Data.DataView dataView = ((DataBindItem)this.Page.GetDataItem()).FKParentTable;
// Sort the table on the caption column
dataView.Sort = "FK_CaptionColumn";
//Override the .DataSource property with the sorted data
((DropDownList)sender).DataSource = dataView;
}
...


If you have any other questions, we will be more than happy to help you.
Best wishes,
Adillis Support
Adillis - IT solutions http://adillis.com
 2/23/2011 10:24:45 AM
Adillis Support
51 posts
adillis.com


Re: Foreign Key Dropdown Sort
Hi Brett,

A new feature will be added to the next release of smartDBforms.NET
which will allow to easily achieve the SORT functionality.

Here is description of the future feature:
===============
Easy sorting of FK parent tables.

There will be two ways for sorting the FK tables:
1) On server side
There will be a way to specify ORDER BY expression for each FK table. The ORDER BY will be executed on database level, which is more efficient for large tables.
The property will be specified either in  .resx  file or as DB Table extended property and will be named for example:
{BaseTableName}.FKSort



2) In-Memory by ADO.NET.
The FKDropDownTemplate will have custom property SORT. It will have the following values Empyt, "ASC", "DESC".
It will allow the data to be sorted before being set to the dropdown list.

This will allow to achieve the sort functionality with no code.




If you have any other questions, we will be more than happy to help you.
Best wishes,
Adillis Support
Adillis - IT solutions http://adillis.com
  Product Forums  smartDBforms.NET  Foreign Key Dro...
Copyright 2006-2012 Adillis Terms Of Use Feedback Contact Us