0

我有以下代码:

代码背后:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;

namespace TestApp2
{
    public partial class hookload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["Rig_ID"].Equals(1))
                MultiView1.ActiveViewIndex = 0;
            else if (Request.QueryString["Rig_ID"].Equals(2))
                MultiView1.ActiveViewIndex = 1;
            else if (Request.QueryString["Rig_ID"].Equals(3))
                MultiView1.ActiveViewIndex = 2;
            else if (Request.QueryString["Rig_ID"].Equals(4))
                MultiView1.ActiveViewIndex = 3;
            else if (Request.QueryString["Rig_ID"].Equals(5))
                MultiView1.ActiveViewIndex = 4;
        }
    }
}

这是我的 aspx 文件:

<%@ Page Title="Shannons Proof of Concept Rig Dashboard" Language="C#" MasterPageFile="~/Site.master"
    AutoEventWireup="true" CodeBehind="hookload.aspx.cs" Inherits="TestApp2._Default" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:MultiView ID="MultiView1" runat="server">
        <asp:View ID="View1" runat="server">
            <asp:SqlDataSource ID="SqlDataSource27" runat="server" ConnectionString="<%$ ConnectionStrings:RigDashConnectionString1 %>"
                SelectCommand="SELECT TOP (30) tbl_rig.name, tbl_stats.Timestamp AS Expr1, tbl_stats.HookLoad, tbl_stats.Rig_ID FROM tbl_rig INNER JOIN tbl_stats ON tbl_rig.rig_id = tbl_stats.Rig_ID WHERE (tbl_stats.Rig_ID = 2) ORDER BY Expr1 DESC">
            </asp:SqlDataSource>
            <h2>
                Rig Hook Load Stats - Previous 10 minutes</h2>
            <p>
                <asp:Chart ID="Chart25" runat="server" DataSourceID="SqlDataSource27" Width="900px"
                    Height="500px" Style="margin-top: 5px" Palette="EarthTones">
                    <Series>
                        <asp:Series Name="Rig 24 Hook Load" XValueMember="Expr1" XValueType="Time" YValueMembers="HookLoad"
                            Legend="Legend" YValuesPerPoint="1" ChartType="Line">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic" WallWidth="0" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend" Title="Legend">
                        </asp:Legend>
                    </Legends>
                </asp:Chart>
            </p>
        </asp:View>
        <asp:View runat="server">
            <asp:SqlDataSource ID="SqlDataSource28" runat="server" ConnectionString="<%$ ConnectionStrings:RigDashConnectionString1 %>"
                SelectCommand="SELECT TOP (30) tbl_rig.name, tbl_stats.Timestamp AS Expr1, tbl_stats.HookLoad, tbl_stats.Rig_ID FROM tbl_rig INNER JOIN tbl_stats ON tbl_rig.rig_id = tbl_stats.Rig_ID WHERE (tbl_stats.Rig_ID = 3) ORDER BY Expr1 DESC">
            </asp:SqlDataSource>
            <h2>
                Rig Hook Load Stats - Previous 10 minutes</h2>
            <p>
                <asp:Chart ID="Chart26" runat="server" DataSourceID="SqlDataSource28" Width="900px"
                    Height="500px" Style="margin-top: 5px" Palette="EarthTones">
                    <Series>
                        <asp:Series Name="Rig 21 Hook Load" XValueMember="Expr1" XValueType="Time" YValueMembers="HookLoad"
                            Legend="Legend" YValuesPerPoint="1" ChartType="Line">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic" WallWidth="0" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend" Title="Legend">
                        </asp:Legend>
                    </Legends>
                </asp:Chart>
            </p>
        </asp:View>
        <asp:View runat="server">
            <asp:SqlDataSource ID="SqlDataSource29" runat="server" ConnectionString="<%$ ConnectionStrings:RigDashConnectionString1 %>"
                SelectCommand="SELECT TOP (30) tbl_rig.name, tbl_stats.Timestamp AS Expr1, tbl_stats.HookLoad, tbl_stats.Rig_ID FROM tbl_rig INNER JOIN tbl_stats ON tbl_rig.rig_id = tbl_stats.Rig_ID WHERE (tbl_stats.Rig_ID = 5) ORDER BY Expr1 DESC">
            </asp:SqlDataSource>
            <h2>
                Rig Hook Load Stats - Previous 10 minutes</h2>
            <p>
                <asp:Chart ID="Chart27" runat="server" DataSourceID="SqlDataSource29" Width="900px"
                    Height="500px" Style="margin-top: 5px" Palette="EarthTones">
                    <Series>
                        <asp:Series Name="Rig 22 Hook Load" XValueMember="Expr1" XValueType="Time" YValueMembers="HookLoad"
                            Legend="Legend" YValuesPerPoint="1" ChartType="Line">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic" WallWidth="0" />
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend" Title="Legend">
                        </asp:Legend>
                    </Legends>
                </asp:Chart>
            </p>
        </asp:View>
    </asp:MultiView>
    <p>
        <a href="..\default.aspx">< Go Back</a>
    </p>
</asp:Content>

现在我的问题是,当我尝试运行它时,我收到消息“当前上下文中不存在名称‘MultiView1’”。我真的不明白为什么我会收到这个错误,但我也是一个菜鸟,所以这并不奇怪。:) 基本上,我在第一页上有一个 asp:gridview 表,我正在尝试传递参数以供此页面处理,因此当有人单击 ~\charts\hookload.aspx?Rig_ID=2 的链接时,它会处理MultiView Index 1,因此它显示 SQL 查询所描述的相关数据图表。

到目前为止,这是我发现的唯一方法,所以如果其他人有更好的主意,相信我,我全神贯注。我一直在努力寻找答案,主要是因为我不知道要搜索什么关键字。任何帮助,将不胜感激。

4

2 回答 2

1

<%@ Page Title="Shannons Proof of Concept Rig Dashboard" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="hookload.aspx.cs" Inherits="TestApp2._Default" %>

您的页面错误地继承了 Inherits="TestApp2._Default"

于 2012-08-24T03:14:37.920 回答
1

您的页面的继承属性必须引用您的支持类的名称。

更正您的继承,如下所示:

<%@ Inherits="TestApp2.hookload" Page Title="Shannons Proof of Concept Rig Dashboard" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="hookload.aspx.cs"  %>

当您更改类名并忘记在 aspx 文件中更正它时会发生这种情况。

于 2012-08-24T03:24:32.650 回答