2012-03-01 71 views
1

由於我正在使用的當前文件系統的性質,我必須從代​​碼隱藏頁面動態訪問ASPX頁面中的數組變量。我已經達到了能夠拉動任何明確聲明的變量的程度,但似乎無法動態拉動它們。從ASPX中的代碼隱藏動態訪問數組變量

代碼背後:

public partial class some_class : System.Web.UI.Page { 
    public string[] array123 = new string[100]; 

    .... 
    protected void Button1_Click(object sender, EventArgs e) { 
     someFunction(); 
    } 

    protected void someFunction() { 
     int i = 1; 
     _TempDt = Locator._New_Locator(value) 

     foreach (DataRow _TempDR in _TempDt.Rows) { 
      array123[i] = Server.UrlEncode(address); 
      i++; 
     } 
    } 
} 

ASPX:

.... 
<asp:Repeater ID="DataList" runat="server"> 
    <ItemTemplate> 
     <label onClick="javascript:popup('page.aspx?key=<%= array123[1] %>')">Get link</label> 
    </ItemTemplate> 
</asp:Repeater> 

這僅拉動陣列中所陳述的(第二)值,並將其需要是動態的與所述中繼器。

謝謝。

+0

不很確定你在這裏問什麼。你想獲得數組的值在中繼器索引的位置嗎?即:中繼器的項目n將顯示陣列的項目n? – 2012-03-01 00:44:29

+0

Shai Cohen,是的,那正是我想要得到的 – sbay 2012-03-01 01:05:41

回答

1

我認爲這是你在找什麼:

<p><%# array123[Container.ItemIndex] %></p> 
+0

,或許你現在可以幫助這個! http://stackoverflow.com/questions/9509022/publishing-asp-net-application-to-the-internet – 2012-03-01 01:00:42

+0

jfmags, 這實際上是我試過,但它會引發編譯錯誤 「CS0103:名稱'容器'在當前上下文中不存在「 我實際上編輯了上面的ASPX頁面代碼以反映它實際上的樣子(我知道它很醜,但這是我必須處理的) – sbay 2012-03-01 01:04:12

+0

您可能錯過了# – jmaglio 2012-03-01 01:10:43

0

試試這個:

<%#DataBinder.Eval的(集裝箱 「的ItemIndex」, 「」)%>