急!急!急!一个关于repeater 嵌套radiobuttonlist 的问题
我在一个repeater 里嵌套了一个radiobuttonlist 控件 代码如下:<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" >
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Question_Name") %>'>
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" EnableViewState="true" >
</asp:RadioButtonList>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("Question_Body") %>' Visible="false"></asp:Label>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
在后台的代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = danxuan(272);
Repeater1.DataBind();
}
}
public static DataTable danxuan(int plistid)
{
string sql = @"SELECT ST_XuanZe.*, PaperDetail.*
FROM PaperDetail INNER JOIN
ST_XuanZe ON PaperDetail.Question_Id = ST_XuanZe.Question_ID
WHERE (PaperDetail.P_List_Id = " + plistid + ")";
DataTable dt = DBHelp.GetDataSet(sql);
return dt;
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RadioButtonList rd = (RadioButtonList)e.Item.FindControl("RadioButtonList1");
string body = ((Label)e.Item.FindControl("Label2")).Text;
string[] tem_body = body.Split('♂');
int counts = tem_body.Length - 1;
char rblstr = 'A';
for (int i = 1; i <= counts; i++)
{
rd.Items.Add(new ListItem(rblstr.ToString() + "、" + tem_body[i - 1].ToString(), rblstr.ToString()));
rd.ID = "rbl" + i.ToString();
rblstr++;
}
}}
protected void Button1_Click(object sender, EventArgs e)
{
string msg = "";
foreach (RepeaterItem item in Repeater1.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
RadioButtonList rd = item.FindControl("RadioButtonList1") as RadioButtonList;
msg += rd.SelectedValue.ToString();
}
}
this.Label1.Text = msg;
}
显示都没有问题 就是我点击按钮时我选择的radiobuttonlist 值就没有了 这是我在选择然后点击按钮 值就在了 为什么高手求救
--------------------编程问答--------------------
--------------------编程问答-------------------- 没有选择到 原因是点击按钮 视乎刷新了 在选就正常了
protected void Button1_Click(object sender, EventArgs e)
{
string msg = "";
foreach (RepeaterItem item in Repeater1.Items)
{
// RadioButtonList 是否已选择了值
RadioButtonList rd = item.FindControl("RadioButtonList1") as RadioButtonList;
msg += rd.SelectedValue.ToString();
}
this.Label1.Text = msg;
}
补充:.NET技术 , ASP.NET