- <asp:DropDownList ID="DropDownList1" runat="server"
- DataSourceID="SqlDataSource12" DataTextField="linkShortDesc"
- DataValueField="linkShortDesc">
- </asp:DropDownList>
- <asp:SqlDataSource ID="SqlDataSource12" runat="server"
- ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
- SelectCommand="SELECT [linkShortDesc] FROM [Links]"></asp:SqlDataSource>
As you can see from the code, we created a new ASP.NET SqlDataSource, provided our connection string and our query we wanted to run. In my case I'm returning a list of links from a table. Now, in our ASP.NET DropDownList code, we can specify a DataValueField and a DataSourceID. The DataSourceID is the ID of the data source we want to link to, and DataValueField is the name of the column we want to display in our drop down list.
Happy coding!
No comments:
Post a Comment