Hai... I'm Doing my project in asp .net(vb .net coding)
If anybody guide me means it would be great pleasure for me...
I want to display names in the list box
So i used the coding:

If Not Page.IsPostBack Then
Try
myda = New SqlDataAdapter("Select name from agent", connection)
ds = New DataSet
myda.Fill(ds, "agent") ListBox2.DataSource = ds
ListBox2.DataTextField = ds.Tables(0).Columns("Lastname").ColumnName.ToString()
ListBox2.DataBind() 
Catch ex As Exception
End Try
End If

Now i want to display count value near the name ...
The below names will be displayed in the listbox when the page loads

For ex:

Thomus
Adson
Thomus
Al-hert
Aroson
Thomus

Here 3 thomus are there ,for this i have to set values like this

For ex:

Thomus,3
Adson,1
Al-hert,1

This should be displayed on the listbox can any one say what to do and how to do with little ex :-/:?: ...

Thanks in advance...

Recommended Answers

All 4 Replies

u should make use of sql by this

select (name + CAST( count (name) AS varchar(10)) ) as NameCount from agent group by name
and also remember to make change in binding expression for testfieldvalue

u should make use of sql by this

select (name + CAST( count (name) AS varchar(10)) ) as NameCount from agent group by name
and also remember to make change in binding expression for testfieldvalue

Problem Solved thanks for ur reply

Yes you can use this query select (name + ',' + convert(varchar(10),count(name))) as NameCount
from agent group by name

you can either use cast or convert function.

how problem was solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.