2014-02-07 5 views
0

그래,이 웹 사이트가 있는데 코드 뒤에 선언 된 여러 개의 배열이 있습니다. 나는 그들을 aspx 페이지에서 사용하려고 노력하고 있지만 일단 제 2 수준 div 요소로 내려 가면 액세스 할 수 없다고 알려줍니다. 참조 코드 : 뒤에보호 수준으로 인해 페이지 필드에 액세스 할 수 없습니다.

코드 :

<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> 

그래서 strTitle, strCitystrCountry이 인해 보호 수준에 액세스 할 수없는 것을 저에게 말한다, 그러나 strFilePath는 : 여기

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(); 
    } 
} 

그리고는 ASP입니다 시원한. div 엘리먼트의 클래스 속성 때문이라고 느낀다. 그렇다면 주위를 둘러 쌀 수있는 방법이 있습니까? 나는 "this"를 사용해 보았지만, 역시 작동하지 않았다.

+0

div의 CSS 클래스는 코드 숨김 변수의 범위에 영향을주지 않습니다. – mason

+0

알아두면 좋을 것 같습니다. 내 문제에 대한 아이디어가 있습니까? – Joseph

+0

ASPX 페이지'data-iview : image = "placeImages /"+ <% = strFilePath [0] %>'에서 이와 같이 문자열을 연결할 수 없습니다. – mason

답변

2

변수가 페이지에 표시 될 수 있도록 보호해야합니다. 기본적으로 비공개입니다. 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]; 
+1

+1. 해답을 사용할 때 지역 코딩 가이드 라인에서 [헝가리 표기법] (http://en.wikipedia.org/wiki/Hungarian_notation)의 사용을 요구하지 않는 한'str' 접두사를 삭제하는 것을 고려하십시오. –

+0

좋은 거래. @ dbugger 감사합니다. 이제는 내가 충분히 이해할 수없는 경우 별도의 질문을 할 새로운 문제가 있습니다. 감사! – Joseph

관련 문제