473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

listbox

Hi,

How to read a string which has comma from a table and to bind to listbox. I want display each item after comma as a different list item. I know i have to use split function but facing problem while implementing.
Aug 21 '07 #1
6 1799
prabunewindia
199 100+
hi friend,
u can split string by any char as ur wish

ex:
string items="one,two,three";
string[] itemArray=items.Split(',');

now u can get
itemArray[0]=one like this

Try it out
Prabu

Hi,

How to read a string which has comma from a table and to bind to listbox. I want display each item after comma as a different list item. I know i have to use split function but facing problem while implementing.
Aug 21 '07 #2
hi friend,
u can split string by any char as ur wish

ex:
string items="one,two,three";
string[] itemArray=items.Split(',');

now u can get
itemArray[0]=one like this

Try it out
Prabu
But, How do I bind that to a listbox.

I am working in asp.net 2.0 and using vb script.

Let us assume i have table "A_desktops" with columns assetcode and swinstalled.

Assecode Swinstalled
D001 sql,vb,Sap
D002 vs 2005, sql 2005
D003 Microsoft SQL Server 2000 Microsoft Office 97, Std Edition SAP

When i bind the data based on asset code say D003 to listbox it bind as Microsoft SQL Server 2000 Microsoft Office 97, Std Edition SAP But i want them to display different listitems after comma.



I have the following code,

Sub ListLoad()
' ||||| DECLARE VARIABLES |||||
Dim strProducts As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(strProducts, dbconn)
Dim objReader As SqlDataReader

Dim itemArray() As String = strProducts.Split(",")


Try
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
lstselectedemployees.Items.Clear()
lstselectedemployees.DataTextField = "Swinstalled"
lstselectedemployees.DataSource = objReader
lstselectedemployees.DataBind()
objReader.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Aug 21 '07 #3
prabunewindia
199 100+
hi friend,

use foreach loop to get strings in string array
inside loop additem
Prabu
But, How do I bind that to a listbox. I have the following code,

Sub ListLoad()
' ||||| DECLARE VARIABLES |||||
Dim strProducts As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(strProducts, dbconn)
Dim objReader As SqlDataReader

Dim itemArray() As String = strProducts.Split(",")


Try
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
lstselectedemployees.Items.Clear()
lstselectedemployees.DataTextField = "Swinstalled"
lstselectedemployees.DataSource = objReader
lstselectedemployees.DataBind()
objReader.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Aug 21 '07 #4
prabunewindia
199 100+
hi friend,
try with this code

string aaa = "";
string[] itemArray=aaa.Split(',');
foreach(string item in itemArray)
{
listbox.Items.Add(item);
}

Prabu
But, How do I bind that to a listbox.

I am working in asp.net 2.0 and using vb script.

Let us assume i have table "A_desktops" with columns assetcode and swinstalled.

Assecode Swinstalled
D001 sql,vb,Sap
D002 vs 2005, sql 2005
D003 Microsoft SQL Server 2000 Microsoft Office 97, Std Edition SAP

When i bind the data based on asset code say D003 to listbox it bind as Microsoft SQL Server 2000 Microsoft Office 97, Std Edition SAP But i want them to display different listitems after comma.



I have the following code,

Sub ListLoad()
' ||||| DECLARE VARIABLES |||||
Dim strProducts As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(strProducts, dbconn)
Dim objReader As SqlDataReader

Dim itemArray() As String = strProducts.Split(",")


Try
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
lstselectedemployees.Items.Clear()
lstselectedemployees.DataTextField = "Swinstalled"
lstselectedemployees.DataSource = objReader
lstselectedemployees.DataBind()
objReader.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Aug 21 '07 #5
hi friend,
try with this code

string aaa = "";
string[] itemArray=aaa.Split(',');
foreach(string item in itemArray)
{
listbox.Items.Add(item);
}

Prabu
Hi prabhu, I used the following code as u said, but i am seeing select swinstalled from a_desktops where assetcode= D067 in the listbox :(

Sub listsplit()
Dim str As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(str, dbconn)
Dim objReader As SqlDataReader
Dim delimStr As String = ","
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
Dim itemArray() As String = str.Split(","c)
Dim item As String
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
For Each item In itemArray
lstselectedemployees.Items.Add(item)
Next
End Sub
Aug 21 '07 #6
prabunewindia
199 100+
hi friend,
i am not getting u da
here u splited the query(str="select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'")

but u should split the string, what u r getting from database know?
so from reader get it to the string and then do the for loop process

i not well with vb.net
but i think u did mistake in that
For Each item In itemArray ****

For Each string item In itemArray (i think this is correct, not sure)
u give the output u r getting, then it is easy to find sol for me
also error if u get so
Prabu

Hi prabhu, I used the following code as u said, but i am seeing select swinstalled from a_desktops where assetcode= D067 in the listbox :(

Sub listsplit()
Dim str As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(str, dbconn)
Dim objReader As SqlDataReader
Dim delimStr As String = ","
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
Dim itemArray() As String = str.Split(","c)
Dim item As String
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
For Each item In itemArray
lstselectedemployees.Items.Add(item)
Next
End Sub
Aug 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.