Question

I'm working on a project of type "ASP.NET dynamic data LINQ to LINQ application".

When i execute my application I'm getting all labels and DropDownLists dynamically binding.

I'm referring this blog.

Now I need to populate those DropDownList based on my criteria. Currently, it is populating all the records which is there in table for that column. How can I customize this DropDownList like I want to select only User with Mak name?

I guess i need to made some linq query here when dropdown populated values? not sure

protected void Page_Load(object sender, EventArgs e)
        {
            if (DropDownList1.Items.Count == 0)
            {
                if (Mode == DataBoundControlMode.Insert || !Column.IsRequired)
                {
                    DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
                }
                PopulateListControl(DropDownList1);
            }

            SetUpValidator(RequiredFieldValidator1);
            SetUpValidator(DynamicValidator1);
        }

enter image description here

Was it helpful?

Solution

In order to customize data in DropDownList control in Dynamic Data site you should use FilterUIHintAttribute class (in your metadata) that allows to replace (or add new filters) default (built-in filters templates) filters.

Consider example of implementing new filter template using built-in filter template for columns of Boolean type (as in the attached picture).

Let's suppose that you have table WorkFlows with column Status of Boolean type (bit for SQL Server) and you would like that DropDownList control has only false value (by default user can choose filter value from All, True, False, and [Not Set] if the column allows null values).

First of all copy built-in filter template Boolean.ascx (you can find it in ~\DynamicData\Filters directory) and then paste one to the same directory. Then rename new filter to StatusBoolean.ascx.

Then you can edit code-behind of StatusBoolean.ascx and delete line with

DropDownList1.Items.Add(new ListItem("True", Boolean.TrueString));

Then you should change metadata for WorkFlows entity:

[FilterUIHint("StatusBoolean")]
public bool Status { get; set; }

That's all.

More information at FilterUIHintAttribute Class.

You can also look my post at ASP.NET Dynamic Data automatically populating a Drop Down list based on Metadata.

OTHER TIPS

I'm assuming that the data type you are binding is a nullable bool (bool?). When assigning the DataSource property, you can use myObjects.Where( o => o.TheNullableBool.HasValue ).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top