1

How can I add a data to my drop down list came from database? My code is this. And when I try using this:

<form id="form1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT * FROM [renovationproject]"></asp:SqlDataSource>
    <br />

Using Dropdownlist input web control:

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"          DataTextField="tasks" DataValueField="workid">
</asp:DropDownList>

It got errors in a webpage that says controls are not allowed to be put here. I only have an empty dropdown right now.

<asp:DropDownList ID="DdLocation" runat="server"></asp:DropDownList>
1
  • What is the error message (specifically) Commented Aug 3, 2011 at 5:56

1 Answer 1

3

There are many ways to add data. You can put them in there literally <asp:listitem>; Or here are some basic ones: http://www.w3schools.com/aspnet/aspnet_databinding.asp

You can also look into creating a <asp:datasource>. I recommend you do this with the wizard first (in desing view, you should have a little arrow block near the dropdown list -- start with "choose data source".

You can also bind with a datatable in your code behind. Google keywords asp:dropdownlist, databind(), dataadapter, dataset, datatable.

Sign up to request clarification or add additional context in comments.

2 Comments

This is what I got in wizard "SqlDataSource1" and nothing happens.
OK -- try deleting the datasource, and also delete the attribute DataSourceID="SqlDataSource1" from your dropdown list. Then try to run the wizard again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.