How to bind dataset value to listbox in asp.net C#?

Posted by Prabu_Spark under ASP.NET on 5/31/2013 | Points: 10 | Views : 6914 | Status : [Member] | Replies : 3
Hi sir,
Tell me the steps to bind dataset value to listbox in asp.net C#. Kindly give me the solution for this
problem.

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Satyapriyanayak on: 5/31/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:ListBox ID="ListBox1" runat="server" Height="242px"
SelectionMode="Multiple" Width="337px"></asp:ListBox>
</form>
</body>
</html>


Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con.Open()
str = "select * from employee"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet
sqlda.Fill(ds, "employee")
ListBox1.DataValueField = "empid"
ListBox1.DataTextField = "empname"
ListBox1.DataSource = ds
ListBox1.DataMember = "employee"
ListBox1.DataBind()
con.Close()
End Sub
End Class


If this post helps you mark it as answer
Thanks

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 5/31/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello You can check this

http://imagirlit.blogspot.in/2012/10/binding-data-into-listbox-in-aspnet.html

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 5/31/2013 [Member] Starter | Points: 25

Up
0
Down
hi

this link is useful for you.

http://forums.asp.net/t/1295655.aspx
http://www.c-sharpcorner.com/Forums/Thread/132596/Controls/NewControls


Thanks,
Bagesh Kumar singh

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response