Binding controls via a datasource is nice and easy, however when you try and change the way the data is displayed in a dropdown for example, Linq can be a pain.
Example 1 – Add text variable flag to show what entry is a primary category and which are secondary categories
<asp:LinqDataSource ID="LDSRentalDefinition"
runat="server" ContextTypeName="DB"
Select="new (ID, (iif(isPrimary==true,' ','+') + Name) as TextValue)"
TableName="Categories" OrderBy="iif(isPrimary==true,' ','+'),Name" >
Weird thing is in the SELECT, IF statements don’t work, but old fashioned IIF statements do.
Still gets me that some C# code works inside the LinqDataSource on a VB page, but some VB works as well.
( || does work where | doesn’t )
Its a nice visual thing for the users as they can see straight away that any child category has a + in front of it in the dropdownlist
Annoyingly I was only allowed a single character inside the ‘’, page would crash otherwise.
Example 2 – add multiple data fields to a single item in the listbox
This is an easier one, but still very powerful to make your UI make more sense to the user
Select="new (ID, (Name + ' ' + Description) as TextValue”
List box items are displayed as “Bob boss”, “John cleaner” rather than just a first name.
No comments:
Post a Comment