sbay
sbay

Reputation: 445

Dynamically accessing array variables from Code Behind in ASPX

Due to the nature of the current file system I am working with I have to dynamically access array variables in ASPX page from the code-behind page. I got it to the point where I am able to pull any one explicitly stated variable, but cannot seem to pull them dynamically.

Code Behind:

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>

This only pulls the stated (2nd) value in the array and it needs to be dynamic with the repeater.

Thanks.

Upvotes: 1

Views: 1687

Answers (2)

jmaglio
jmaglio

Reputation: 776

I think this is what you are looking for:

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

Upvotes: 1

Shai Cohen
Shai Cohen

Reputation: 6249

Try this:

< %#DataBinder.Eval(Container, "ItemIndex", "")%>

Upvotes: 0

Related Questions