Dynamic Control ID's
Posted on 2004-04-21
Is it possible (and if so how) to dynamically create ID's for .NET "buttons" when using the repeater control. I have a table which holds a list of button names / button text strings. I bind my repeater to the returned data set and then I want to loop through the returned records and create a button for each returned record with the asp:button having the ID as specified in the table. I've tried using :
<asp:button id=<%#DataBinder.Eval(Container.DataItem, "ButtonID")%> Text='<%#DataBinder.Eval(Container.DataItem, "ButtonText")%>' runat="server" cssclass="buttonStyle"></asp:button>
This doesnt work and displays an error showing :
Parser Error Message: '<%#DataBinder.Eval(Container.DataItem, "ButtonID")%>' is not a valid identifier.
If I just set the ID to a fixed name e.g.btnTest then it displays fine and each button displays the correct text.
I'm fairly new to .NET so if you could dumb down any answers it would be appreciated :-)