Radiobuttonlist управления повторителем всегда возвращает нулевое значение

Я использую приведенный ниже код для чтения значения списка переключателей. Но он всегда возвращает ноль. Пожалуйста, помогите мне решить эту проблему.

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&nbsp;</asp:ListItem>
                <asp:ListItem Text="Neutral">Neutral&nbsp;&nbsp;</asp:ListItem>
                <asp:ListItem Text="Disagree">Disagree</asp:ListItem>
                </asp:RadioButtonList>
            </td>

        </tr>
    </table>
</ItemTemplate>

Мой код соизволения здесь, ..


person user1804985    schedule 07.11.2012    source источник
comment
Покажите нам html, и вы выберете один из вариантов из списка радиообъявлений?   -  person Adil    schedule 07.11.2012
comment
вы получаете ценность в других файлах, таких как lbl_slno и lbl_ques?   -  person शेखर    schedule 07.11.2012
comment
RadioButtonList radiobtn = (RadioButtonList) item.FindControl (rdbtn);   -  person Mohit    schedule 07.11.2012
comment
krshekhar да у меня есть два других значения.   -  person user1804985    schedule 07.11.2012
comment
Почему бы тебе не отладить код?   -  person Adrian Iftode    schedule 07.11.2012
comment
Это не работает. Пожалуйста, помогите мне исправить эту ошибку ..   -  person user1804985    schedule 07.11.2012


Ответы (1)


Попробуйте получить значение через .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;
        }
person Community    schedule 07.11.2012
comment
Потому что это то же самое, что и выше - person शेखर; 07.11.2012