如何使用vb.net将SQL数据绑定到HTML下拉列表中。 [英] How to bind SQL data into HTML dropdownlist using vb.net.

查看:75
本文介绍了如何使用vb.net将SQL数据绑定到HTML下拉列表中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何使用vb.net将sql数据绑定到html下拉列表。

当页面加载事件开始时,下拉列表应该填充。



i已经将databind编入dropdownlist,它工作正常。

但是我的sql表列应该如下所示,我无法做到预期的输出。 br />


MCH-批次| 0;非mch - 批次| 1



但我的预期产量是,



MCH-Batch
非mch-Batch



请给我一个解决方案。

提前谢谢



我尝试了什么:



如何使用vb.net将sql数据绑定到html下拉列表。

解决方案

为什么不使用服务器端Dropdownlist和SQLDatasource从sql获取数据然后您在设计时可以选择Dropdownlist并配置其数据源属性以便使用sqldatasource并将display member属性和value member属性设置为sql查询所需的字段。


在源中

<![CDATA [<%@ Page Language =VBAutoEventWireup =falseCodeFile =Default6.aspx.vbInherits =Default6%>] ]> 


 <%@       语言  =  VB    AutoEventWireup   =  false < span class =code-attribute>   CodeFile   =  Default6.aspx.vb   继承  =  Default6   % >  

< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN < span class =code-attribute> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >

< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = 服务器 >
< 标题 > < /标题 >
< / head >
< body >
< 表单 id = form1 runat = server >
< div < span class =code-keyword>>
< asp:SqlDataSource ID = SqlDataSource1 runat = server

< span class =code-attribute> ConnectionString = <%

Hi all,
how to bind sql data into html dropdownlist using vb.net.
the dropdownlist should fill when the pageload event starts.

i have tryied databind into dropdownlist , its working fine.
but my sql table column should come like below, that i can't do the expected output.

MCH- Batch|0 ; non mch - Batch|1

But my expected output is,

MCH-Batch
non mch-Batch

Please drop me a solution.
thanks in advance

What I have tried:

how to bind sql data into html dropdownlist using vb.net.

解决方案

Why don't you use server side Dropdownlist and SQLDatasource to get data from sql then you in the design time you may select the Dropdownlist and configure its datasource property to use sqldatasource and set the "display member" property and the "value member" property to the fields you need from your sql query.


In The Source

<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>]]>


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

            ConnectionString="<%


这篇关于如何使用vb.net将SQL数据绑定到HTML下拉列表中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆