Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 9-Jul-16 2:33am

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.
 
Share this answer
 
v2
In The Source
<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>]]>
 
Share this answer
 
ASP.NET
<%@ 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="<%$ ConnectionStrings:StreamNETConnectionString %>" 
            SelectCommand="SELECT TOP (10) * FROM Worker"></asp:SqlDataSource>
        <asp:DropDownList ID="DropDownList1" runat="server" 
            DataSourceID="SqlDataSource1" DataTextField="FullName" 
            DataValueField="WorkerID">
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
v2
VB.NET
Partial Class Default6
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        DropDownList1.SelectedValue = 1
    End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900