日期:2014-05-18  浏览次数:20445 次

如何对RadioButtonList数据绑定???
在后台已经处理好

  this.DataList1.DataSource = dt;
  this.DataList1.DataBind();


在前台
asp:Label
  ID="Label5" runat="server" Text='<%# Eval("题目") %>'></asp:Label>
这是绑定一个数据


可是我RadioButtonList要绑定四个数据

asp:RadioButtonList ID="RadioButtonList2" runat="server" RepeatDirection="Horizontal" >
  </asp:RadioButtonList><br />

要如何写绑定???

------解决方案--------------------
4楼的代码没有实现rdlDataBind方法,应该不能编译通过的。实际上,使用绑定表达式,你就无需再去处理DataList的ItemDataBound事件了。

使用4楼的设计代码丝毫不变
HTML code

<asp:datalist id="dlOption" runat="server">
                                    <ItemTemplate>
                                        <TABLE id="Table2" cellSpacing="1" cellPadding="1" width="300" border="1">
                                            <TR>
                                                <TD>
                                                    <asp:Label id=lbAsk runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"examAsk") %>'>
                                                    </asp:Label></TD>
                                            </TR>
                                            <TR>
                                                <TD>
                                                    <asp:RadioButtonList id=rblOption runat="server" DataSource='<%# rdlDataBind(DataBinder.Eval(Container.DataItem,"examOption").ToString()) %>'>
                                                    </asp:RadioButtonList></TD>
                                            </TR>
                                        </TABLE>
                                    </ItemTemplate>
                                </asp:datalist>