[英]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: 使用Dropdownlist输入Web控件:
<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>
; 您可以将它们放在字面上
<asp:listitem>
; Or here are some basic ones: http://www.w3schools.com/aspnet/aspnet_databinding.asp 或这里是一些基本的: http : //www.w3schools.com/aspnet/aspnet_databinding.asp
You can also look into creating a <asp:datasource>
. 您也可以考虑创建
<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.
Google关键字asp:下拉列表,databind(),dataadapter,数据集,datatable。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.