p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Databases (http://p2p.wrox.com/forumdisplay.php?f=62)
-   -   problem with dropdown list in datagrid (http://p2p.wrox.com/showthread.php?t=29612)

marty_nguyen May 21st, 2005 05:21 PM

problem with dropdown list in datagrid
 
Hi,

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>
                                        <ItemTemplate>
                                            <asp:Label id="lblProdLine" runat="server" text='<%# Container.DataItem("Product Line") %>'></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <asp:DropDownList id="DD_ProdLine_SS" runat="server" datavaluefield="Product Line" datatextfield="Product Line" datasource="<%#GetProdLine_SS()%>"></asp:DropDownList>
                                        </EditItemTemplate>
                                    </asp:TemplateColumn>
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

dataAdapter.Fill(dataSet)

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
i.e:
PL 1
PL 2
PL 3


HELP PLEASE!!!

Martin

peace95 May 22nd, 2005 06:16 PM

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




All times are GMT -4. The time now is 08:12 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.