dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: dropdown NOT displaying only unique items

  1. #1
    Join Date
    Jul 2011
    Posts
    14

    dropdown NOT displaying only unique items

    so I have put space in the drop down that I am having trouble with.

    what im am trying to do is have the dropdown run from a database colume which is not a key which has multiable products with the same names but I dont what them displayed more then once I want them to select it from that dropdown and then display the multiable choices in the next dropdown thanks for the help in advance

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList ID="Catagory" runat="server" AutoPostBack="True">
    <asp:ListItem>Select</asp:ListItem>
    <asp:ListItem>Doors</asp:ListItem>
    <asp:ListItem>Loading Dock</asp:ListItem>
    <asp:ListItem>Overhead Lifting</asp:ListItem>
    <asp:ListItem>Storage Products</asp:ListItem>
    <asp:ListItem>Ergonomic Lifts</asp:ListItem>
    <asp:ListItem>Conveyors</asp:ListItem>
    <asp:ListItem>Materials Handling</asp:ListItem>
    <asp:ListItem>Safety Environmental</asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    
    
    <asp:DropDownList ID="SubCatagory" runat="server" AutoPostBack="True" 
    DataSourceID="SqlDataSource1" DataTextField="SubCatagory1" 
    DataValueField="Id" AppendDataBoundItems="True">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:kingConnectionString %>" 
    SelectCommand="SELECT DISTINCT * FROM [Products] WHERE ([Catagory] = @Catagory) ORDER BY [SubCatagory1]">
    
    
    <SelectParameters>
    <asp:ControlParameter ControlID="Catagory" Name="Catagory" 
    PropertyName="SelectedValue" Type="String" />
    </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <asp:DropDownList ID="Name" runat="server" AutoPostBack="True" 
    DataSourceID="SqlDataSource2" DataTextField="Name" 
    DataValueField="Id" AppendDataBoundItems="True">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:kingConnectionString %>" 
    SelectCommand="SELECT * FROM [Products] WHERE ([Id] = @Id)">
    <SelectParameters>
    <asp:ControlParameter ControlID="SubCatagory" Name="Id" 
    PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
    DataKeyNames="Id" DataSourceID="SqlDataSource3" EnableModelValidation="True" 
    Height="50px" Width="125px">
    <Fields>
    <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" 
    ReadOnly="True" SortExpression="Id" />
    <asp:BoundField DataField="Catagory" HeaderText="Catagory" 
    SortExpression="Catagory" />
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
    <asp:BoundField DataField="Benefit1" HeaderText="Benefit1" 
    SortExpression="Benefit1" />
    <asp:BoundField DataField="Benefit2" HeaderText="Benefit2" 
    SortExpression="Benefit2" />
    <asp:BoundField DataField="Benefit3" HeaderText="Benefit3" 
    SortExpression="Benefit3" />
    <asp:BoundField DataField="Benefit4" HeaderText="Benefit4" 
    SortExpression="Benefit4" />
    <asp:BoundField DataField="Benefit5" HeaderText="Benefit5" 
    SortExpression="Benefit5" />
    <asp:BoundField DataField="Benefit6" HeaderText="Benefit6" 
    SortExpression="Benefit6" />
    <asp:BoundField DataField="Benefit7" HeaderText="Benefit7" 
    SortExpression="Benefit7" />
    <asp:BoundField DataField="Benefit8" HeaderText="Benefit8" 
    SortExpression="Benefit8" />
    <asp:BoundField DataField="Benefit9" HeaderText="Benefit9" 
    SortExpression="Benefit9" />
    <asp:BoundField DataField="Benefit10" HeaderText="Benefit10" 
    SortExpression="Benefit10" />
    <asp:BoundField DataField="Links1" HeaderText="Links1" 
    SortExpression="Links1" />
    <asp:BoundField DataField="Links2" HeaderText="Links2" 
    SortExpression="Links2" />
    <asp:BoundField DataField="Links3" HeaderText="Links3" 
    SortExpression="Links3" />
    <asp:BoundField DataField="Links4" HeaderText="Links4" 
    SortExpression="Links4" />
    <asp:BoundField DataField="Links5" HeaderText="Links5" 
    SortExpression="Links5" />
    <asp:BoundField DataField="Info" HeaderText="Info" SortExpression="Info" />
    <asp:BoundField DataField="Image1" HeaderText="Image1" 
    SortExpression="Image1" />
    <asp:BoundField DataField="Image2" HeaderText="Image2" 
    SortExpression="Image2" />
    <asp:BoundField DataField="Image3" HeaderText="Image3" 
    SortExpression="Image3" />
    <asp:BoundField DataField="Image4" HeaderText="Image4" 
    SortExpression="Image4" />
    <asp:BoundField DataField="Image5" HeaderText="Image5" 
    SortExpression="Image5" />
    <asp:BoundField DataField="Quantity" HeaderText="Quantity" 
    SortExpression="Quantity" />
    <asp:BoundField DataField="OriginalPrice" HeaderText="OriginalPrice" 
    SortExpression="OriginalPrice" />
    <asp:BoundField DataField="PurchasePrice" HeaderText="PurchasePrice" 
    SortExpression="PurchasePrice" />
    <asp:BoundField DataField="Supplier" HeaderText="Supplier" 
    SortExpression="Supplier" />
    <asp:BoundField DataField="ProductType" HeaderText="ProductType" 
    SortExpression="ProductType" />
    <asp:BoundField DataField="ContactId" HeaderText="ContactId" 
    SortExpression="ContactId" />
    <asp:BoundField DataField="SubCatagory1" HeaderText="SubCatagory1" 
    SortExpression="SubCatagory1" />
    <asp:BoundField DataField="SubCatagory2" HeaderText="SubCatagory2" 
    SortExpression="SubCatagory2" />
    </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:kingConnectionString %>" 
    SelectCommand="SELECT * FROM [Products] WHERE ([Id] = @Id)">
    <SelectParameters>
    
    <asp:ControlParameter ControlID="Name" Name="Id" PropertyName="SelectedValue" Type="Int32" />
    
    </SelectParameters>
    
    </asp:SqlDataSource>
    
    </div>
    
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    242

    Re: dropdown NOT displaying only unique items

    Distinct would not work properly on *. You need to have column name

    Original Query
    Code:
    SELECT DISTINCT * FROM [Products] WHERE ([Catagory] = @Catagory
    Change it to
    Code:
    SelectCommand="SELECT DISTINCT ProdName FROM [Products] WHERE ([Catagory] = @Catagory) ORDER BY [SubCatagory1]">
    Hope this helps. If it does, then rate it.
    ----
    Rohit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)