473,396 Members | 2,033 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,396 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 1800
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.