日期:2014-05-17 浏览次数:20457 次
<script runat="server"> String[] d = { "A", "B", "C" ,"D","E"}; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { rbanswer.DataSource = new string[] { "111", "333" }; rbanswer.DataBind(); for(int i=0;i<rbanswer.Items.Count;i++) { rbanswer.Items[i].Text = d[i] + " " + rbanswer.Items[i].Text; } } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <form id="form1" runat="server"> <asp:RadioButtonList ID="rbanswer" runat="server" RepeatColumns="0" RepeatDirection="Vertical" RepeatLayout="Table" TextAlign="Right"></asp:RadioButtonList> </form> </body> </html>
------解决方案--------------------
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { RadioButtonList Radiobuttonlist1 = e.Item.FindControl("Radiobuttonlist1") as RadioButtonList; Radiobuttonlist1.Items.Add(new ListItem("A" + DataBinder.Eval(e.Item.DataItem, "字段1").ToString(), "A")); Radiobuttonlist1.Items.Add(new ListItem("B" + DataBinder.Eval(e.Item.DataItem, "字段2").ToString(), "B")); Radiobuttonlist1.Items.Add(new ListItem("C" + DataBinder.Eval(e.Item.DataItem, "字段3").ToString(), "C")); Radiobuttonlist1.Items.Add(new ListItem("D" + DataBinder.Eval(e.Item.DataItem, "字段4").ToString(), "D")); }