user1804985
user1804985

Reputation: 297

Repeater control radiobuttonlist always return null value

I'm using the below code to read radio button list value. But it always returns null. Please help me to fix this issue.

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>

My deign code is here,..

Upvotes: 0

Views: 871

Answers (1)

user1711092
user1711092

Reputation:

Try by getting value through .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;
        }

Upvotes: 2

Related Questions