Inland Empire .NET User's Group Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Adding a static item to dropdownlist when it...Expand / Collapse
Author
Message
Posted 4/26/2008 11:46:34 PM


Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 2/10/2009 12:52:26 PM
Posts: 50, Visits: 221
Hi,
today in the class, i was asked how to bind the dropdownlist to a sqldatasource, as wells as adding some static items. It is easy, you set the AppendDataBoundItems property of the dropdownlist to true, and add your static item., an example is below: there is a dropdownlist binded to sqldatasource which gets the categories from the northwind database, and also a static listitem is added to the dropdownlist. you can also see, how we can use requiredfieldvalidator :
[php]
ropDownList ID="listCategories" runat="server"
DataSourceID="SqlDataSource1" DataTextField="CategoryName"
DataValueField="CategoryID" AppendDataBoundItems="True">

ropDownList>
Text="(Required)" ControlToValidate="listCategories" runat="server" />





ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">

[/php]


test