读书人

怎么对RadioButtonList数据绑定?

发布时间: 2012-04-18 15:01:59 作者: rapoo

如何对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> 

读书人网 >asp.net

热点推荐