Repeater控件中如何用后台代码获取改行对象的某一个属性的值?
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound"> <ItemTemplate> <table style="text-align:left;width:800px"> <tr"> <td style="width:10%"><h4><%# Container.ItemIndex + 1%></h4></td> <td style="width:90%"><h4><asp:HiddenField ID="HF1" runat="server" Value='<%#Eval("题号")%>'/><%#Eval("内容")%></h4></td> </tr> <% string type = %><%#Eval("类型")%><% if (type == "单选"){ %> <tr> <td style="width:10%"></td> <td style="width:90%"> <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataTextField="内容" DataValueField="选项" /> </td> </tr> <% }else if (type == "多选"){ %> <tr> <td style="width:10%"></td> <td style="width:90%"> <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="内容" DataValueField="选项" /> </td> </tr> <% }else{ %> <tr"> <td style="width:10%">答案:</td> <td style="width:90%"><asp:TextBox ID="TextBox1" runat="server" Width="98%"></asp:TextBox></td> </tr> <% } %> </table> </ItemTemplate> </asp:Repeater>
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { Topic topic = e.Item.DataItem as Topic; switch (topic.类型) { case "单选": RadioButtonList rpt1 = e.Item.FindControl("RadioButtonList1") as RadioButtonList; rpt1.DataSource = topic.选项; rpt1.DataBind(); break; case "多选": CheckBoxList rpt2 = e.Item.FindControl("CheckBoxList1") as CheckBoxList; rpt2.DataSource = topic.选项; rpt2.DataBind(); break; default: break; } }