0

Hi
I have dropdownlist populated from database.My requirement is to count the number of records for each dropdownlist item like:
Toyota(15)
Honda(10)
BMW(20)

I have used

ddlMake.Items.Add(datatable.Rows.Count)

but it shows records in below format

Toyota
Honda
BMW
(15)
(10)
(20)

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by fawadkhalil
0

Hello there

You can do this with the resultset from your dataset source.
You can write the Group query to select eg:

select ProductID , ProductName and Value as Contactinate Productname + RowCount from yourtable

And then bind it to your DDL.

Mark as fixed if it helps you

Edited by reach_yousuf: n/a

0

Acutually im populating DDL from one table(CarMake) and counting no. of records from another table(CarSale) means how many cars are there for sale of a certain CarMake.

0

Hi there

Use the Query like this . The result is tested in 'Adventureworks' database

Select 
product.ProductID, 
product.Name, 
ProductInventory.Quantity,
product.Name+'('+ cast(ProductInventory.Quantity as nvarchar(5))+ ')' as Value
from Production.product 
inner join Production.ProductInventory
on ProductInventory.ProductID = product.ProductID

Then bind this result to your DDL.

Mark as solved if it helps you

Edited by reach_yousuf: n/a

0
select MakeName + '(' + cast((select count(*) from CarSale p where p.MakePK = m.PK) as varchar) + ')' dispField, m.PK
 from CarMake m

For MS SQL 2000 above code, assumes PK as primary key for join of CarSale and CarMake. Also assuming that you will need the PK as value member.
- PadteS

Acutually im populating DDL from one table(CarMake) and counting no. of records from another table(CarSale) means how many cars are there for sale of a certain CarMake.

0

Wow Padtes thats exactly what i was looking for.Thank u very much
Thanks Yousaf to u also for your valuable suggestions.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.