在当前背景下不存在

时间:2012-08-24 03:05:22

标签: c# asp.net

我有以下代码:

背后的代码:

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 Query所描述的相关数据图表。

这是迄今为止我发现的唯一方法,所以如果其他人有更好的想法,相信我,我都是耳朵。我一直在努力找到答案,主要是因为我不知道要搜索哪些关键字。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分: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”

答案 1 :(得分:1)

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

按如下方式更正您的继承:

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

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