Posted: 10/4/2011
Hi could someone please advise me on the following I'm new. I have adrop down list which I use to sort data from my gridview table. I would like to only display unique items in my dropdown list and not duplicates. Also, I would like to see my whole table in gridview when I open the page and let the user filter it as they like. However, at the moment I don't see the whole table when I open the page, only the drop down list. Here is my code: Please help :)
<%@ Page Title="BikeList" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="BikeList.aspx.cs" Inherits="Pages_BikeList" %> <asp:Content ID="Content2" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h1><a id="top">View Our Range</a></h1> <p>Below is a complete list of our bikes. Use the drop down box to filter down box to filter the list by manufacturer.</p> Manufacturer: <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Make" DataValueField="Make" AppendDataBoundItems="true"> <asp:ListItem Value="">Make a Selection</asp:ListItem> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT [Make], [BikeID] FROM [Bike] ORDER BY [BikeID]"> </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="BikeID" DataSourceID="SqlDataSource2" HorizontalAlign="Center" EnableSortingAndPagingCallbacks="True"> <Columns> <asp:BoundField DataField="BikeID" HeaderText="BikeID" InsertVisible="False" ReadOnly="True" SortExpression="BikeID" /> <asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" /> <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" /> <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" ItemStyle-CssClass="textalignright" /> <asp:BoundField DataField="Capacity" HeaderText="Capacity" ItemStyle-CssClass="textalignright" SortExpression="Capacity" /> <asp:BoundField DataField="SalePrice" DataFormatString="{0:C}" ItemStyle-CssClass="textalignright" HeaderText="SalePrice" SortExpression="SalePrice" /> <asp:BoundField DataField="DealerPrice" DataFormatString="{0:C}" ItemStyle-CssClass="textalignright" HeaderText="DealerPrice" SortExpression="DealerPrice" /> <asp:CheckBoxField DataField="Featured" HeaderText="Featured" SortExpression="Featured" /> <asp:ImageField DataImageUrlField="Thumbnail" DataImageUrlFormatString="~\Images\{0}" HeaderText="Thumbnail"> </asp:ImageField> <asp:HyperLinkField DataNavigateUrlFields="Image" DataNavigateUrlFormatString="~\Images\{0}" HeaderText="Image" Text="Larger Image" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Bike] WHERE ([Make] = @Make)"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="Make" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:SqlDataSource> </asp:Content>
Posted: 10/6/2011
Are you sure your datasource is bringing sufficient data to fill the GridView?