1

I just started working with ASP.NET and Visual Studio 2008. I want to create something fairly straightforward, yet I don't know how to approach it yet.

I have access to an Oracle table that I'd like to leverage to create a report interface. For simplicity's sake, let's assume that this table only has three columns:

  1. REPORT_DATE
  2. SUCCESSES
  3. FAILURES

Now, the proposed ASP.NET interface will only have two components:

  1. DropDownList
  2. GridView (or table, whichever is simpler)

The DropDownList will allow the user to select a date (e.g. 11/8/2012). The GridView will then populate based on the user selection. It will display all columns except "REPORT_DATE". In this hypothetical scenario, the GridView will display "SUCCESSES" and "FAILURES". Essentially, it would follow this SQL statement:

SELECT * FROM MyTable WHERE REPORT_DATE=insertSelectedReportDateHere;

So far, I have successfully populated the DropDownList with REPORT_DATE using Visual Studio's GUI to connect to my database and table. However, I'm unsure how to implement the population of the GridView based on my selection. I assume this will require hard-coding AJAX, but I wasn't sure how powerful Visual Studio's GUI was.

Is there a way to do this using the GUI? Or do I have to do it programmatically? Any suggestions or resources that I should reference?

Thank you!

2 Answers 2

1

This can most certainly be done without resorting to doing it programatically:

        <asp:SqlDataSource
            ID="dropDownDS"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:connectionString %>"
            SelectCommand="select distinct reportdate from reports"></asp:SqlDataSource>
        <asp:DropDownList ID="ddlReports" runat="server"
            AutoPostBack="True"
            DataSourceID="dropDownDS"
            DataTextField="reportdate"
            DataValueField="reportdate" />
        <asp:SqlDataSource ID="gridDS"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:connectionString %>"
            SelectCommand="SELECT * FROM Reports WHERE ReportDate = @ReportDate">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlReports" Name="reportdate" PropertyName="SelectedValue" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="gvReports"
            runat="server"
            AutoGenerateColumns="False"
            DataKeyNames="ReportId"
            DataSourceID="gridDS">
            <Columns>
                <asp:BoundField DataField="ReportId" HeaderText="ReportId" Visible="False" />
                <asp:BoundField DataField="ReportDate" HeaderText="ReportDate" />
                <asp:BoundField DataField="Successes" HeaderText="Successes" />
                <asp:BoundField DataField="Failures" HeaderText="Failures" />
            </Columns>
        </asp:GridView>

Welcome to the wrold of ASP.NEt and to stackoverflow!

Sign up to request clarification or add additional context in comments.

Comments

1

1) make sure AutoPostBack property of your dropdown is set to true

2) Add dropdownlist1_selectedindexchanged event to your code and there add the code to fill DataGrid based on dropdownlist selection

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.