简体   繁体   English

如何在ASP.NET VB.NET的下拉列表框中添加数据?

[英]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.

相关问题 如何使用asp.net vb.net在代码中使用会话 - How I can use sessions in my code using asp.net vb.net 编辑代码。如何使用vb.net从asp.net的下拉列表中显示gridview - Edited code.How to display gridview from dropdown list in asp.net using vb.net 如何使用asp.net(vb.net)将文本框中的数据保存到mysql数据库 - How to save data from text box to mysql database using asp.net (vb.net) 我可以在ASP.Net书面VB.net中通过单击按钮将新行添加到datagrid视图吗 - Can i add new row to datagrid view with a button click in ASP.Net written VB.net 有什么想法如何使用asp.net vb.net向我的Web应用程序添加文本通信? - any ideas how to add text communication to my web application using asp.net vb.net? 如何使用VB.net在ASP.NET(.NET 2.0)中创建分层数据网格 - How can I create a hierarchical datagrid in asp.net (.net 2.0) using VB.net 如何在 Visual Studio 2019 中添加 Adobe Pdf 查看器(Asp.net Vb.net 项目)? - How can I add Adobe Pdf viewer in Visual Studio 2019( Asp.net Vb.net Project)? 如何在下拉列表ASP.Net和VB.Net应用程序中将当前用户设置为默认值 - How can I set current user as default value in the drop down list ASP.Net and VB.Net application 如何在我的asp.net和vb.net注册表单中集成QapTcha(jQuery captcha插件) - How can I integrate QapTcha ( jQuery captcha plugin) in my asp.net and vb.net registration form DotNetNuke - 如何将自定义ASP.NET / VB.NET文件合并到DNN站点? - DotNetNuke - How do I incorporate my custom ASP.NET/VB.NET files into a DNN site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM