简体   繁体   English

由于保护级别,页面字段无法访问

[英]Page fields are inaccessible due to protection level

Okay, so I've got this website and I've got several arrays that are declared in the code behind. 好的,所以我有这个网站,我有几个在后面的代码中声明的数组。 I'm trying to use them on the aspx page, but it tells me that they are inaccessible once I get down to a second level div element. 我试图在aspx页面上使用它们,但是它告诉我,一旦我进入第二级div元素,它们就无法访问。 See code: 看代码:

Code behind: 代码背后:

string[] strFilePath = new string[5];
string[] strTitle = new string[5];
string[] strCity = new string[5];
string[] strCountry = new string[5];


protected void Page_Load(object sender, EventArgs e)
{
    string constr = 
  @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TravelJoansDB.mdb;";
    string cmdstr = "SELECT TOP 5 * FROM Table2 ORDER BY TravelDate";
    OleDbConnection con = new OleDbConnection(constr);
    OleDbCommand com = new OleDbCommand(cmdstr, con);

    con.Open();
    OleDbDataReader reader = com.ExecuteReader();
    for (int i = 0; i < 5; i++)
    {
        reader.Read();
        strFilePath[i] = reader[2].ToString();
        strTitle[i] = reader[6].ToString();
        strCity[i] = reader[7].ToString();
        strCountry[i] = reader[8].ToString();
    }
}

And here's the ASP: 这是ASP:

<a href="BlogPosts.aspx" id="iview"> 
    <!-- Slide 1 -->
    <div data-iview:image="placeImages/" + <%= strFilePath[0] %>>
    <!-- Caption 1 -->
        <div class="iview-caption" data-x="400" data-y="400" 
              data-transition="wipeRight"  data-speed="700">
           <h3><%= strTitle[0] %></h3>
           <%= strCity[0] %>, <%= strCountry[0] %>
       </div>
    </div>

So it tells me that strTitle , strCity and strCountry are inaccessible due to its protection level, but strFilePath is cool. 因此它告诉我strTitlestrCitystrCountry由于其保护级别而无法访问,但strFilePath很酷。 I have a feeling that it is because of the class property of the div element. 我觉得这是因为div元素的class属性。 If that is so, is there a way to get around that? 如果是这样,有没有办法解决这个问题? I tried using "this", but that didn't work either. 我尝试使用“这个”,但这也不起作用。

Need to make the variables protected so they can be seen in your page. 需要保护变量,以便在页面中看到它们。 They are private by default. 它们默认是私有的。 The strFilePath isn't cool either, but is likely being ignored. strFilePath也不酷,但很可能被忽略。

protected string[] strFilePath = new string[5];
protected string[] strTitle = new string[5];
protected string[] strCity = new string[5];
protected string[] strCountry = new string[5];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM