1

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.

2
  • Not quite sure what you are asking here. Do you want to get the value of the array at the position of the repeater index? ie: item n of the repeater will display item n of the array? Commented Mar 1, 2012 at 0:44
  • Shai Cohen, yes, that is exactly what I am trying to get Commented Mar 1, 2012 at 1:05

2 Answers 2

1

I think this is what you are looking for:

<p><%# array123[Container.ItemIndex] %></p>
Sign up to request clarification or add additional context in comments.

4 Comments

perhaps you can help wiht this one now! stackoverflow.com/questions/9509022/…
jfmags, this is actually what I tried but it throws a compilation error "CS0103: The name 'Container' does not exist in the current context" i actually edited the ASPX page code above to reflect what it actually looks like (i know its ugly, but this is what i have to work with)
you were probably missing the #
sorry - it should be this <p><%# array123[Container.ItemIndex] %></p>
0

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.