We help IT Professionals succeed at work.

Gridview: show 2 rows even tho sp has more than 2 rows

Camillia
Camillia asked
on
Please look at output below.
On the page, I have a listview and a dropdown list

1. I bind column "hcProvider" to listview. This is ok.
2. I bind businessName colum to a dropdownList but I need to show only 2 rows but it shows 5
3. Gridview should have 2 rows but has 5 because I have 5 rows from stored proc

See attached screenshot of how it looks like
So, I need to show 2 rows because I have "Test Business33" and "Username test" as BusinessName. Dropdownlist needs to show 2 businessnames. Listview is good.

How can I show 2 rows and bind to gridview when stored proc has 5 rows? If there's no solution to this, I'll talk to my manager
Id         businessName      hcId      HCproviderName
3	Test Business33	18	Behnaz Wafa
3	Test Business33	 1	 Bob1 Jones
3	Test Business33	 11	 pp333 ppp
3	Test Business33	 16	 yy fff
39	Username test	12	officer 1 llll

Open in new window

Doc2.docx
Comment
Watch Question

Hi,

Can you update your query in stored proc to retrieve only two rows?

if yes, update your query as given below:

SELECT Top 2 field1, field2 ... fieldN
FROM YourTableName

You will get only two rows from the SP.

This will work for MSSQL.

- Deepak Lakkad
if i do that, i wont get all the hcproviders...i have 5 unique hcproviders. I need all thos e5 BUT only 2 rows of businessname.
can you post code of your sp?

Commented:
you can use two different sps for this purpose

select Distinct businessName   From TABLENAME  - will return only 2 rows.

using 2 different sp is ok for u?
Commented:
BTW, how did u bind ur listview, dropdownlist and gridview?

r u using Datasource control? Or using code-behind u r binding?

 here is another soln:

if you are having a datatable that has rows of these values, then

Datatable businessNames = dt.DefaultView.ToTable(true, "businessName");
urDropDownlist.DataSource = businessNames;
urDropDownlist.DataTextField = "businessName";
urDropDownlist.DataValueField = "Id";

Open in new window


here dt denotes the DataTable Name which has all the selected 5 rows.

yes, 2 SPs could be a good way. Let me look at your solution.