Wrox Programmer Forums
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 21st, 2005, 05:21 PM
Registered User
Join Date: Apr 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to marty_nguyen
Default problem with dropdown list in datagrid


Can someone help me with this prob i'm having with a dropdown list in a datagrid please!!!

I have a datagrid with a template column listing the "product line" of the record:

<asp:TemplateColumn HeaderText="Prod Line">
                                        <HeaderStyle width="50px"></HeaderStyle>
                                            <asp:Label id="lblProdLine" runat="server" text='<%# Container.DataItem("Product Line") %>'></asp:Label>
                                            <asp:DropDownList id="DD_ProdLine_SS" runat="server" datavaluefield="Product Line" datatextfield="Product Line" datasource="<%#GetProdLine_SS()%>"></asp:DropDownList>
The datasource of the dropdown list in edit mode comes from a function GetProdLine_SS returning a dataset:

Function GetProdLine_SS() As System.Data.DataSet

strSQL = "SELECT [Product Line] FROM [Product_Lines] WHERE [Product Line Group 2] = 'Single Sales'"

dbCommand.CommandText = strSQL
dbCommand.Connection = dbConnection

dataAdapter.SelectCommand = dbCommand


Return dataSet

End Function

The problem is the dropdown list is showing values which are returned from the dataset (returned from the function) ASWELL as the product lines from the records in the datagrid.

e.g. The records in the datagrid are:
Product Product Line
A PL 1
B PL 2
C PL 2

and the product lines in the product_line table are:
PL 1
PL 2
PL 3

the dropdown list in the productline table are showing values:
PL 1
PL 2
PL 2
PL 1
PL 2
PL 3

I only want it to show values from the product_lines table
PL 1
PL 2
PL 3


Old May 22nd, 2005, 06:16 PM
Friend of Wrox
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts

Martin, I am very new to this forum, but my suggestions are:
  1) look at the database structures, the primary and foreign keys and their relationships (1-to-many, or many-to-many) of the two tables you are linking or using in your drop-down list. From what u listed, it seems that the Product has multiple single sales (Product Line);
   2) try using the word "DISTINCT" in the select statement to obtain a single occurance of the Product Line, create a new table, New_Product_Line_Tbl. Then Display in the drop-down List, the Product and the New_Product_Line_Tbl, using the LEFT JOIN;
   3) look at #1 and #2 outside of the drop-down-list, to see what is actually going on at this point.

Hope this helps, hard to say with out looking at the structure of your tables.

Good Luck

Similar Threads
Thread Thread Starter Forum Replies Last Post
can we bind datagrid and dropdown list rakeshgv SQL Server 2000 0 August 21st, 2006 02:13 AM
Dropdown list in a datagrid maddy137 ASP.NET 1.0 and 1.1 Professional 0 May 19th, 2006 02:05 PM
populating a dropdown list within a datagrid in C# akshay144 General .NET 0 May 12th, 2006 04:44 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.