Asp – How to populate UpdatePanel in Repeater in ASPX (not code-behind)

asp.netasp.net-ajax

I have a Repeater which displays a list of items (in a grid-like/table view). When a user clicks an item, I display an UpdatePanel under this item with additional information relevant to the item (similar to Accordion control). I know how to populate the elements of the UpdatePanel in code-behind (I pass the ID of the selected element in the Repeater control as CommandArgument, get additional info for this ID, and set up the text fields of the active UpdatePanel controls). But I'm wondering if I could set up binding directly in the ASPX (instead of code-behind). When I used the <%= %> syntax to assign text fields of the UpdatePanel control the values of the page properties, e.g. <%= Comment %>, it sort of worked, but it changed the fields of all UpdatePanels in the repeater. Is there any way to bind the active UpdatePanel to the current values and leave already bound UpdatePanels unchanged?

Best Answer

Are you looking to display a container that displays additional information? Is there other activity in the "box" that requires it be an updatepanel?

<asp:repeater>
   <itemtemplate>
      <%# Eval("Name") %> <%# Eval("LastName") %><br />
      <span onclick="$get('<%# Eval("Id") %>')">View Age</span>
      <div id="<%# Eval("Id")%>" style="display:none;">
          Age: <%# Eval("Age") %>
      </div>
   <itemtemplate>
</asp:repeater>

Ithink that's right, some syntax may be off a bit (typing without intellisense). Would that work? I used ID as a unique identifier for the div id and the onclick command. You could also use jquery, asp:controls or whatever else you wanted.

Related Topic