Asp.net C#Update Panels和DropDown列出了数据绑定

时间:2014-04-28 19:50:35

标签: c# asp.net data-binding drop-down-menu updatepanel

可能有助于您更好地了解问题的背景知识:

这是我大学初级项目的一部分。我的JP是挥发性有机化合物传感器,但我想创建一个网站,以图形方式查看记录的水平作为额外的奖励。现在情况不是很好,因为我只是先行功能。话虽这么说,我所做的可能不是最好的做法 - 但我愿意接受如何做得更好的建议!我现在有一个2.5级系统 - 我计划很快制作3层。所有5个下拉列表都有一个onselectedindexchange触发器来更新它下面的下拉列表的内容。

Zipcode下拉列表(数据绑定到查询以返回DISTINCT邮政编码列表)

MonitorID下拉列表(数据绑定根据上面选择的邮政编码返回Monitor表中的所有MonitorID。)

年份下拉列表(数据绑定以返回监视器已运行的年份列表。例如," 2013,2014"可能会返回并显示在此下拉列表中。)

月份下拉列表(数据绑定以返回基于所选年份可用的月份列表)

一天下拉列表(数据绑定以返回基于所选月份的可用天数列表)

我的问题是,当我选择一年时,我的月日下拉列表没有更新,我不知道为什么。这是graph.aspx.cs代码

                      

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="Graph_Outter_Zip" runat="server">
                <ContentTemplate>
                    Choose a Zip-code:
                    <asp:DropDownList ID="Graph_DropDownListZip" runat="server" DataSourceID="GetDistinctZip_BL" DataTextField="Zip" DataValueField="Zip" AutoPostBack="True" OnSelectedIndexChanged="Graph_DropDownListZip_SelectedIndexChanged">
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="GetDistinctZip_BL" runat="server" SelectMethod="GetDistinctZip" TypeName="Sentient.WebManager.MonitorLevel_BL"></asp:ObjectDataSource>
                    <br />
                    Choose a MonitorID:
                    <asp:DropDownList ID="Graph_DropDownListMonitor" runat="server" AutoPostBack="True" DataSourceID="GetMonitorIDs" DataTextField="MonitorID" DataValueField="MonitorID">
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="GetMonitorIDs" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetMonitorIDsFromZip" TypeName="Sentient.WebManager.MonitorLevel_BL">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="Graph_DropDownListZip" DefaultValue="97603" Name="zipCode" PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:ObjectDataSource>

                    <br />
                    Choose a year/month/day to view:
                    <div class="yearDD">
                        Year:<asp:DropDownList ID="GRAPH_yearDropDropList" runat="server" DataSourceID="GetYearFromMonitorID_BL" DataTextField="Year" DataValueField="Year" OnSelectedIndexChanged="GRAPH_yearDropDropList_SelectedIndexChanged"></asp:DropDownList> 
                        <asp:ObjectDataSource ID="GetYearFromMonitorID_BL" runat="server" SelectMethod="GetYearFromMonitorID" TypeName="Sentient.WebManager.MonitorLevel_BL" OldValuesParameterFormatString="original_{0}">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="Graph_DropDownListMonitor" DefaultValue="1" Name="MonitorID" PropertyName="SelectedValue" Type="Int32" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </div>
                    <div class="monthDD">
                        Month:<asp:DropDownList ID="GRAPH_monthDropDownList" runat="server" DataSourceID="GetMonthFromMonitorID" DataTextField="Month" DataValueField="Month" OnSelectedIndexChanged="GRAPH_monthDropDownList_SelectedIndexChanged"></asp:DropDownList>
                        <asp:ObjectDataSource ID="GetMonthFromMonitorID" runat="server" SelectMethod="GetMonthFromMonitorID" TypeName="Sentient.WebManager.MonitorLevel_BL">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="Graph_DropDownListMonitor" DefaultValue="1" Name="MonitorID" PropertyName="SelectedValue" Type="Int32" />
                                <asp:ControlParameter ControlID="GRAPH_yearDropDropList" DefaultValue="2014" Name="Year" PropertyName="SelectedValue" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </div>
                    <div class="dayDD">
                        Day:<asp:DropDownList ID="GRAPH_dayDropDownList" runat="server" DataSourceID="GetDayFromMonitorID" DataTextField="Day" DataValueField="Day" OnSelectedIndexChanged="GRAPH_dayDropDownList_SelectedIndexChanged"></asp:DropDownList>
                        <asp:ObjectDataSource ID="GetDayFromMonitorID" runat="server" SelectMethod="GetDayFromMonitorID" TypeName="Sentient.WebManager.MonitorLevel_BL" OldValuesParameterFormatString="original_{0}">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="Graph_DropDownListMonitor" DefaultValue="1" Name="MonitorID" PropertyName="SelectedValue" Type="Int32" />
                                <asp:ControlParameter ControlID="GRAPH_yearDropDropList" DefaultValue="2014" Name="Year" PropertyName="SelectedValue" Type="String" />
                                <asp:ControlParameter ControlID="GRAPH_monthDropDownList" DefaultValue="04" Name="Month" PropertyName="SelectedValue" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </div>

                    <asp:Button ID="ViewGraphBtn" runat="server" Text="View Graph" OnClick="ViewGraphBtn_Click" />

                    <asp:Chart ID="Graph" runat="server" DataSourceID="LevelAndTime" OnLoad="Graph_Load" Height="500px" Width="500px">
                        <Series>
                            <asp:Series Name="Level" ChartType="Line" XValueMember="Time" YValueMembers="Level"></asp:Series>
                        </Series>
                        <ChartAreas>
                            <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
                        </ChartAreas>
                    </asp:Chart>
                    <asp:ObjectDataSource ID="LevelAndTime" runat="server" OnSelecting="LevelAndTime_Selecting" SelectMethod="GetLevelAndTimeFromDate" TypeName="Sentient.WebManager.MonitorLevel_BL" OldValuesParameterFormatString="original_{0}">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="Graph_DropDownListMonitor" DefaultValue="1" Name="MonitorID" PropertyName="SelectedValue" Type="Int32" />
                            <asp:ControlParameter ControlID="GRAPH_yearDropDropList" DefaultValue="2014" Name="Year" PropertyName="SelectedValue" Type="String" />
                            <asp:ControlParameter ControlID="GRAPH_monthDropDownList" DefaultValue="4" Name="Month" PropertyName="SelectedValue" Type="String" />
                            <asp:ControlParameter ControlID="GRAPH_dayDropDownList" DefaultValue="13" Name="Day" PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:ObjectDataSource>

                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Graph_DropDownListZip" EventName="SelectedIndexChanged" />
                    <asp:AsyncPostBackTrigger ControlID="Graph_DropDownListMonitor" EventName="SelectedIndexChanged" />
                    <asp:AsyncPostBackTrigger ControlID="GRAPH_yearDropDropList" EventName="SelectedIndexChanged" />
                    <asp:AsyncPostBackTrigger ControlID="GRAPH_monthDropDownList" EventName="SelectedIndexChanged" />
                    <asp:AsyncPostBackTrigger ControlID="GRAPH_dayDropDownList" EventName="SelectedIndexChanged" />
                </Triggers>
            </asp:UpdatePanel>
    </div><!--End Content DIV-->
 </div><!--End ContentWrapper DIV-->
</form>

这是MonitorLevel_BL.cs业务层类代码。没有太多的业务规则,所以它非常简单。是的我将构造函数硬编码为b / c我很沮丧:)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sentient.WebPersistence.VOCMSDataSetTableAdapters;
using Sentient.WebPersistence;

namespace Sentient.WebManager
{
    public class MonitorLevel_BL
    {
        //Constructor
        public MonitorLevel_BL()
        {
            zipCode = "97601";
            monitorID = 1;
            serialNumber = 0;
            vocID = 0;
            vocName = "";
            protectionInfo = "";
            symptomInfo = "";
            dangerZone = 0;
            year = "2014";
            month = "05";
            day = "15";
        }

    private string _zipCode;
    private int _monitorID;
    private int _serialNumber;
    private int _vocID;
    private string _vocName;
    private string _protectionInfo;
    private string _symptomInfo;
    private int _dangerZone;
    private string _year;
    private string _month;
    private string _day;

    //Setters and Getters
    public string zipCode
    {
        set { _zipCode = value; }
        get { return _zipCode; }
    }

    public int monitorID
    {
        set { _monitorID = value; }
        get { return _monitorID; }
    }

    public int serialNumber
    {
        set { _serialNumber = value; }
        get { return _serialNumber; }
    }

    public int vocID
    {
        set { _vocID = value; }
        get { return _vocID; }
    }

    public string vocName
    {
        set { _vocName = value; }
        get { return _vocName; }
    }

    public string protectionInfo
    {
        set { _protectionInfo = value; }
        get { return _protectionInfo; }
    }

    public string symptomInfo
    {
        set { _symptomInfo = value; }
        get { return _symptomInfo; }
    }

    public int dangerZone
    {
        set { _dangerZone = value; }
        get { return _dangerZone; }
    }

    public string year
    {
        set { _year = value; }
        get { return _year; }
    }

    public string month
    {
        set { _month = value; }
        get { return _month; }
    }

    public string day
    {
        set { _day = value; }
        get { return _day; }
    }

    public VOCMSDataSet.DistinctZipcodesDataTable GetDistinctZip()
    {
        DistinctZipcodesTableAdapter distinctZip = new DistinctZipcodesTableAdapter();
        return distinctZip.GetDistinctZipcodes();

    }

    public VOCMSDataSet.SP_GetYearFromMonitorIDDataTable GetYearFromMonitorID(int MonitorID)
    {
        SP_GetYearFromMonitorIDTableAdapter yearFromMonitorID = new SP_GetYearFromMonitorIDTableAdapter();
        return yearFromMonitorID.GetYearFromMonitorID(MonitorID);
    }

    public VOCMSDataSet.SP_GetMonthFromMonitorIDDataTable GetMonthFromMonitorID(int MonitorID, string Year)
    {

        SP_GetMonthFromMonitorIDTableAdapter month = new SP_GetMonthFromMonitorIDTableAdapter();
        return month.GetMonthFromMonitorID(MonitorID, Year);
    }

    public VOCMSDataSet.SP_GetDayFromMonitorIDDataTable GetDayFromMonitorID(int MonitorID, string Year, string Month)
    {
        SP_GetDayFromMonitorIDTableAdapter day = new SP_GetDayFromMonitorIDTableAdapter();
        return day.GetDayFromMonitorID(MonitorID, Year, Month);
    }

    public VOCMSDataSet.SP_GetMonitorIDsFromZipDataTable GetMonitorIDsFromZip(string zipCode)
    {
        SP_GetMonitorIDsFromZipTableAdapter monitorIDs = new SP_GetMonitorIDsFromZipTableAdapter();
        return monitorIDs.GetMonitorIDsFromZip(zipCode);
    }

    public VOCMSDataSet.SP_GetRawDataToBeDLDataTable GetRawDataToBeDL( int monitorID )
    {
        SP_GetRawDataToBeDLTableAdapter rawData = new SP_GetRawDataToBeDLTableAdapter();
        return rawData.GetRawDataToBeDL(monitorID);
    }

    public VOCMSDataSet.SP_GetLevelAndTimeFromDateDataTable GetLevelAndTimeFromDate(int MonitorID, string Year, string Month, string Day)
    {
        SP_GetLevelAndTimeFromDateTableAdapter levelTime = new SP_GetLevelAndTimeFromDateTableAdapter();
        return levelTime.GetLevelAndTimeFromDate(MonitorID, Year, Month, Day);
    }

}

我已经对持久层进行了单元测试,并且查询返回了正确的信息,因此我不打算发布这些信息。是否存在某些我在年/月/日下拉列表中缺失的设置?

0 个答案:

没有答案