日期:2014-05-18 浏览次数:21100 次
<asp:DataList ID="DataList1" runat="server" Height="241px" Width="775px" >
                    <ItemTemplate>
                        <table>
                            <tr>
                                <td>
                                    <%#Container.ItemIndex+1 %>
                                    、<asp:Label ID="timu" runat="server" Text='<%#Eval("question") %>'></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                <asp:RadioButtonList ID="RadioButtonList1" runat="server" >
                                    <asp:ListItem Value="A"></asp:ListItem>
                                    <asp:ListItem Value="B"></asp:ListItem>
                                    <asp:ListItem Value="C" ></asp:ListItem>
                                    <asp:ListItem Value="D" ></asp:ListItem>
                                    
                                </asp:RadioButtonList>
 private void dlOption_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {
            if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
            {
                RadioButtonList rbt=(RadioButtonList)e.Item.FindControl("rblOption");
                string data=Convert.ToString(DataBinder.Eval(e.Item.DataItem,"examOption"));
                DataTable dtOpt=this.radblBind(data);
                for(int i=0;i<dtOpt.Rows.Count;i++)
                {
        //直接用ListItem绑定            ListItem it=new ListItem(dtOpt.Rows[i]["strOpt"].ToString(),dtOpt.Rows[i]["strLet"].ToString());
                    rbt.Items.Add(it);
                }
//    用DataBind绑定RadioButtonList            rbt.DataSource=new DataView(dtOpt);
//                rbt.DataTextField="strOpt";
//                rbt.DataValueField="strLet";
//                rbt.DataBind();
            }
        }