CodeSmith Community
Your Code. Your Way. Faster!

New EntityDropDownList and BoundEntityDropDownField controls

rated by 0 users
This post has 8 Replies | 3 Followers

Top 10 Contributor
Posts 925
Points 35,460
swin Posted: 02-19-2007 9:40 AM

I've been using the following controls for a while now and thought it about time I made them into templates - so find a suitable patch attached!

EntityDropDownList - Derives from a DropDownList, but adds a few extra features such as the ability to add a null item (adds a child ListItem), make it readonly(converts it to a label), make the control required (uses a RequiredFieldValidator) and it supports type ahead (javascript).

example use:

<data:EntityDropDownList runat="server" ID="myfieldDDL" DataSourceID="productsDataSource" DataTextField="ProductName" DataValueField="ProductID"
AppendNullItem="true"
NullItemText="<select a value>"
Required="true"
ReadOnly="false"
FriendlyName="My drop down field"
ErrorText="*"
RequiredErrorMessage="This drop down is required"
CaseSensitiveKeySort="true"
/>
 

BoundEntityDropDownField - As above but derived from BoundField so that it can be used within a grid (EntityGridView). It caches the data so that it is only read once for all the bound rows.

example use:

<data:EntityGridView runat="server" ID="gridView" DataSourceID="productsDataSource"
    DataKeyNames="ProductID"
    AutoGenerateColumns="false"
    AutoGenerateEditButton="true"
    AllowPaging="true"
    AllowSorting="true">
    <Columns>
            <asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="True" SortExpression="ProductID" />
            <asp:BoundField DataField="ProductName" HeaderText="Product Name" SortExpression="ProductName" />
            <data:BoundEntityDropDownField DataField="SupplierID" HeaderText="Supplier" SortExpression="SupplierID"
DataSourceID="suppliersDataSource"
DataTextField
="CompanyName"
DataValueField="SupplierID"
AppendNullItem="true" />
            <data:BoundEntityDropDownField DataField="CategoryID" HeaderText="Category" SortExpression="CategoryID" DataSourceID="categoriesDataSource" DataTextField="CategoryName" DataValueField="CategoryID" AppendNullItem="true" />
    </Columns>
    </data:EntityGridView>
   
    <data:ProductsDataSource runat="server" ID="productsDataSource" sort="ProductName" EnableSorting="true" EnablePaging="true" SelectMethod="GetPaged" />
    <data:CategoriesDataSource runat="server" ID="categoriesDataSource" Sort="CategoryName" />
    <data:SuppliersDataSource runat="server" ID="suppliersDataSource" Sort="CompanyName" />

hth

swin
 

------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
  • | Post Points: 75
Top 10 Contributor
Posts 742
Points 17,965

swin,

 That is awesome! I have applied the patch on your behalf (rev. 490)
 

Mike Shatny
--------------------------------------------------------------
Member of the .netTiers team http://www.nettiers.com
--------------------------------------------------------------

Top 75 Contributor
Posts 79
Points 1,860

Yep, thats excellent, thanks swin Big Smile

 

  • | Post Points: 35
Top 10 Contributor
Posts 925
Points 35,460

Thanks guys.

Hey Mike, good job on adding them to the web admin so quickly.

Cheers

swin 

------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
  • | Post Points: 35
Not Ranked
Posts 2
Points 40
Is there a reason the SelectedValue does not show up in IntelliSense for this control?
  • | Post Points: 35
Top 10 Contributor
Posts 925
Points 35,460

It's because it doesn't appear in the base ASP.Net DropDownList.

I don't know why it doesn't appear - I guess Microsoft might know!

hth

swin 

------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
  • | Post Points: 35
Top 10 Contributor
Posts 742
Points 17,965

The DesignerSerializationVisibility attribute is used to suppress the visibility in design-time. The question is why Wink

        [Browsable(false)]
        [DesignerSerializationVisibility(0)]
        [Themeable(false)]
        [DefaultValue("")]
        [Bindable(true, 1)]
        public virtual string SelectedValue { get; set; }

Mike Shatny
--------------------------------------------------------------
Member of the .netTiers team http://www.nettiers.com
--------------------------------------------------------------

  • | Post Points: 35
Top 25 Contributor
Posts 164
Points 3,275

It would be great if this stuff was added to the documentation wiki

 

-Jeff Martin C# MCSD
  • | Post Points: 35
Top 10 Contributor
Posts 925
Points 35,460

Done!, although help on the wiki is always welcomeWink

swin

------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
  • | Post Points: 5
Page 1 of 1 (9 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems