[英]Repeater control radiobuttonlist always return null value
我正在使用以下代码来读取单选按钮列表值。 但它总是返回null。 请帮我解决这个问题。
foreach (RepeaterItem item in repeaterItems.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
lbl_slno = (Label)item.FindControl("id");
lbl_ques = (Label)item.FindControl("lblques");
radiobtn = (RadioButtonList)item.FindControl("rdbtn");
string radio_value = radiobtn.SelectedItem.Value;
//radio_value return "Object reference not set to an instance of an object."
}
}
<ItemTemplate>
<table cellspacing="0" width="100%" align="center">
<tr>
<td style="width: 42px;" class="cu_style" >
<asp:Label ID="id" runat="server" Text='<%#Bind("fld_id")%>'></asp:Label>
</td>
<td style="width: 503px;" class="cu_style">
<asp:Label ID="lblques" runat="server" Text='<%#Bind("fld_Question")%>'></asp:Label>
</td>
<td style="width: 80px;" class="cu_style" colspan="3">
<asp:RadioButtonList ID="rdbtn" Width="229px" runat="server" RepeatDirection="Horizontal" >
<asp:ListItem Text="Agree">Agree </asp:ListItem>
<asp:ListItem Text="Neutral">Neutral </asp:ListItem>
<asp:ListItem Text="Disagree">Disagree</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
</ItemTemplate>
我的设计代码在这里,..
尝试通过.SelectedValue
获取价值
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
var rdbList = item.FindControl("rdbtn") as RadioButtonList;
// Get the selected value
string selected = radiobtn.SelectedValue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.