本文介绍了我的单选按钮列表自动回发时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hiiiiiii,
我从数据库问题及其答案中检索出一个数据列表中的单选按钮列表
我检索单选按钮列表中的答案,到目前为止我还没有任何问题.
我将属性autopostback = true设置为对第一个和第二个单选按钮项都有效,但在第三个项中有问题.
以下是我的数据列表和单选按钮
hiiiiiii,
I have a radiobutton list in a datalist retrived from the database question and its answers
I retrive the answers in the radiobutton list i do not have any problem so far.
I set the property autopostback =true it works good for the first and second radio button items but there is a problem in the third item.
Below is my datalist and radio button
<asp:DataList ID="datalist_iq" runat="server" DataKeyField="id" BorderColor="Red">
<ItemTemplate>
<table border="1">
<tr>
<td>
<asp:Label ID="label_question_head" runat="server" Style="word-wrap: break-word" Width="310px" Height="91px" Font-Bold="true" ForeColor="Maroon">
<%#Eval("q_head") %>
</asp:Label>
</td>
</tr>
<tr>
<td rowspan="2">
<asp:RadioButtonList ID="RadioButton1" AutoPostBack="true" OnSelectedIndexChanged="RadioButton1_SelectedIndexChanged" DataTextField="a_head" DataValueField="result" runat="server" Visible="true" >
</asp:RadioButtonList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
这就是背后的代码
and this is the code behind
protected void RadioButton1_SelectedIndexChanged(object sender, EventArgs e)
{
Label_result.Text = "good";
foreach (DataListItem dli in datalist_iq.Items)
{
rblfilteritem = (RadioButtonList)dli.FindControl("RadioButton1");
foreach (ListItem item in rblfilteritem.Items)
{
if (item.Selected)
item.Selected = true;
}
Label_result.Text = rblfilteritem.SelectedItem.Text;
}
推荐答案
这篇关于我的单选按钮列表自动回发时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!