How to set a control ID in ListView Template dynamically?
Posted
by citronas
on Stack Overflow
See other posts from Stack Overflow
or by citronas
Published on 2010-03-17T10:19:12Z
Indexed on
2010/03/17
10:21 UTC
Read the original article
Hit count: 427
A have a ListView that is rendered with multiple items.
Now I want to toggle some HTML attributes with JQuery. Therefore it would be best to have access to these elements via an unique ID.
But trying to create a "dynamic" and therefore unique ID by
<tr runat="server" ID='<%# this.GetUniqueID() %>'>
</tr>
results in an error that tells me that the ID needs to be simple and cannot be set by a call to a method.
I know that I can dynamically create controls in the code-behind and set the ID there. But in this case, I'd rather like to let the content be rendered by the ListView itself.
That brings me to the conclusion that the idea of setting a dynically ID in the Template is totally wrong. How can I achieve the desired behaviour?
© Stack Overflow or respective owner