Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I retrieve the value from a Dictionary using a Repeater's ItemIndex?
    primarykey
    data
    text
    <p>I was given a page that I need to modify and it has a Repeater with an ItemTemplate that contains the fields to enter a person's address. Each address field looks something like this</p> <pre><code>&lt;input type="text" id="line1&lt;%# ((RepeaterItem)Container).ItemIndex + 1%&gt;" name="line1&lt;%# ((RepeaterItem)Container).ItemIndex + 1%&gt;" /&gt; </code></pre> <p>You can see that we are appending the ItemIndex of the repeater onto the end of the html id and name fields for the text box. </p> <p>In the Code-behind we have a class called DataProxy which is basically a dictionary that is built off of Request.Params and we normally use it to re-populate a form with what a user entered. For example, they put data on a form, submit it, but validation fails because a couple of fields are empty, but we want to re-populate what they had previously entered. We would do that like this:</p> <pre><code>&lt;input type="text" name="myTextBox" id="myTextBox" value="&lt;%: DataProxy["myTextBox"].ToString() %&gt;" /&gt; </code></pre> <p>Normally this works great, but it's not working inside this repeater and I believe it is because the DataBind for the repeater occurs after we have already searched the DataProxy dictionary for our value. This is the code I'm using:</p> <pre><code>&lt;input type="text" id="line1&lt;%# ((RepeaterItem)Container).ItemIndex + 1%&gt;" name="line1&lt;%# ((RepeaterItem)Container).ItemIndex + 1%&gt;" value="&lt;%# DataProxy["line1" + (((RepeaterItem)Container).ItemIndex + 1).ToString()] %&gt;" /&gt; </code></pre> <p>Is there a way that I can access my DataProxy dictionary with the ItemIndex property from the Repeater?</p> <p>Just a note, my repeater is being Data-bound in Page_Load().</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload