I'm trying to generate HTML dynamically, in a way that looks a bit like MVC. However I'm trying to achieve this in Webforms.
I managed to pass a list to my aspx page, but using the properties in the html attributes doesn't seem to work:
My aspx page:
<% For Each question As WorkOrderQuestionDAO In Session("WorkOrderQuestions") %>
<tr>
<td style="width: 620px"><%= question.Question %></td>
<td style="width: 300px">
<% Select Case question.WorkOrderAnswerTypeID
Case 1 %>
<asp:RadioButtonList ID='<%# question.QuestionID %>' runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="-1">YES</asp:ListItem>
<asp:ListItem Value="0">NO</asp:ListItem>
</asp:RadioButtonList>
<%Exit Select
Case 2 %>
<asp:RadioButtonList ID='<%# question.QuestionID %>' runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="-1">YES</asp:ListItem>
<asp:ListItem Value="0">NO</asp:ListItem>
<asp:ListItem Value="1">NA</asp:ListItem>
</asp:RadioButtonList>
<% Exit Select
End Select%>
</td>
</tr>
<% Next %>
So I try to set the ID of each RadioButtonList automatically, by trying to insert the question.QuestionID property. However the error i'm getting is:
The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example:
I tried:
ID='<%# question.QuestionID %>'
ID='<%= question.QuestionID %>'
ID='<%= Eval("question.QuestionID") %>'
At this point I don't know what syntax to use. I don't think it should be to hard, but I couldn't find an answer using Google and find it hard to come up with the proper search terms.
The <tr>, <td> and <asp:RadioButtonList> generation goes fine by the way.
Aucun commentaire:
Enregistrer un commentaire