开发者

How can I add data to my dropdown list box in ASP.NET VB.NET?

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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜