1 Replies - 1461 Views - Last Post: 25 February 2015 - 10:05 AM

#1 RustyAMcM  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 192
  • Joined: 21-January 15

Gridview VB/ASP.NET Filtering on Dropdown

Posted 25 February 2015 - 07:50 AM

I have the following code which works great it allows you to select a date in a calendar and queries a database to get all entries created on that date. However now I am trying to add 2 dropdown menu's for additional sorting to be able to sort the results by Operator and Item. I have been searching for an answer to this but cannot find any solutions if it has been solved please point me in right direction if not any help at all would be great.

Here is the asp code:
<%@ Page Language="VB" Debug="true" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Chi-Touch Web Application</title>
    <style type="text/css">
        .auto-style1 {
            width: 251px;
            height: 98px;
        }
        #TextArea1 {
            width: 783px;
            height: 246px;
        }
    </style>
</head>
    
    
<body>
    <form id="Main" runat="server">
        
    <header>
<img alt="Chi&amp;#149Touch" class="auto-style1" src="chitouch-logo.png" /><asp:Image ID="Image1" runat="server" ImageAlign="Top" />
        <asp:HyperLink ID="HyperLink1" runat="server" BackColor="#3399FF" BorderColor="Blue" BorderStyle="Ridge" Font-Bold="True" NavigateUrl="~/Default2.aspx" Width="101px">ChiTouch Sort</asp:HyperLink>
        <br />
    </header>
        <div style="margin-left: 40px">

        
    
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px" SelectedDate="" VisibleDate="">
            <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
            <NextPrevStyle VerticalAlign="Bottom" />
            <OtherMonthDayStyle ForeColor="#808080" />
            <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
            <SelectorStyle BackColor="#CCCCCC" />
            <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
            <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
            <WeekendDayStyle BackColor="#FFFFCC" />
        </asp:Calendar>
    
    
        <br />
        Operator:&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="OperatorList" runat="server" DataSourceID="SqlDataSource2" DataTextField="OperatorName" DataValueField="OperatorName" AppendDataBoundItems="True" AutoPostBack="True" EnableViewState="True">
            
        </asp:DropDownList>
        <br />
        Item :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="ItemList" runat="server" DataSourceID="SqlDataSource3" DataTextField="Item" DataValueField="Item" AutoPostBack="True" AppendDataBoundItems="True">
        </asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Items]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Operators]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCTROW [Account_Data_Complete_Query.Account] AS [Account], [Account_Data_Complete_Query.Operator] AS [Operator], [Account_Data_Complete_Query.Item] AS [Item], [Account_Data_Complete_Query.Date] AS [Date], Sum([Account_Data_Complete_Query.Worked]) AS [Worked], Sum([Account_Data_Complete_Query.Count]) AS [Count] FROM [Account_Data_Complete_Query] WHERE (([Date] = ?) AND [Operator] = ?)
GROUP BY [Account_Data_Complete_Query.Account], [Account_Data_Complete_Query.Operator], [Account_Data_Complete_Query.Item], [Account_Data_Complete_Query.Date]">
            <SelectParameters>
                <asp:ControlParameter ControlID="Calendar1" Name="Date" PropertyName="SelectedDate" Type="DateTime" DefaultValue="" />
               
                <asp:ControlParameter ControlID="OperatorList" Name="Operator" PropertyName="SelectedValue" DefaultValue="My Name is Nobody" />
                <asp:ControlParameter ControlID="ItemList" Name="Item" PropertyName="SelectedValue" DefaultValue="Nothing" />
               
            </SelectParameters>
        </asp:SqlDataSource>
        
  
        <asp:GridView ID="GridView1" runat="server" ItemType="Operator" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowSorting="True">
            <Columns>
                <asp:BoundField DataField="Account" HeaderText="Account" SortExpression="Account" />
                <asp:BoundField DataField="Operator" HeaderText="Operator" SortExpression="Operator" />
                <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item" />
                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
                <asp:BoundField DataField="Worked" HeaderText="Worked" SortExpression="Worked" />
                <asp:BoundField DataField="Count" HeaderText="Count" SortExpression="Count" />
                
            </Columns>
        </asp:GridView>
        
  
        <br />
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="OperatorDataTestWebDataSetTableAdapters.Account_Data_Complete_QueryTableAdapter"></asp:ObjectDataSource>
        <br />
       
    
    </div>
    </form>
</body>
</html>



And here is the code for my dropdown lists as you can see they are blank AGAIN I have tried several things and nothing works.
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Calendar1_Selectionchanged(sender As Object, e As EventArgs) Handles Calendar1.Selectionchanged

    End Sub

    Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged

    End Sub

    Protected Sub OperatorList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles OperatorList.SelectedIndexChanged
        If Not OperatorList.SelectedValue.Equals(Nothing) Then


        End If
    End Sub

    Protected Sub ItemList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ItemList.SelectedIndexChanged

    End Sub
End Class


Please help I am stuck I do not have any experience with asp net this is all programmed on the fly learning as I go please let me know also if there is a better way of doing this as I am learning as I work thru this.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Gridview VB/ASP.NET Filtering on Dropdown

#2 RustyAMcM  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 192
  • Joined: 21-January 15

Re: Gridview VB/ASP.NET Filtering on Dropdown

Posted 25 February 2015 - 10:05 AM

Ok I have managed to get this to work with one filter field by addingthe following code:

FilterExpression="[Operator]= '{0}' <%-- AND[Item]= '{1}'--%>"


And in the Parameters:
<asp:ControlParameter Name="OperatorName" ControlID="OperatorList" PropertyName="SelectedValue" />
        <%--<asp:ControlParameter Name="Item" ControlID="ItemList" PropertyName="SelectedValue" />--%>


Now my problem is I want this to be able to use both dropdowns to filter BUT with nether of them having to have a value selected AND it only showing the results of both filters if active...

any ideas?

If i uncomment the commented out sections I have to select a value from both boxes to be able to filter and this is not what I want the OR works better but gives me all values that match ether one OR the other boxes which is wrong as well...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1