I am populating about 10 comboboxes by grouping the data in my database by the column name. So the combobox can be used to filter content.
Heres my function
private void SetFilterDataSource(RadComboBox comboBox, string columnName)
{
var query = (from p in productContext.Products
where p.ProductRange != ""
group p by p.ProductRange into pGroup
select new
{
ProductRange = pGroup.Key
});
comboBox.DataSource = query;
comboBox.DataBind();
}
At present this would be repeated 10 times for each combobox. So i was wondering if there was a way to make this dynamic based on a string that was passed to it?
you can write extension and create static method that creates dynamic group by many queries on column names and values using lambda expressions.
See the following link
http://blogs.msdn.com/b/mitsu/archive/2008/02/07/linq-groupbymany-dynamically.aspx