0

I have following radio button list:

<asp:RadioButtonList ID="RdoBtnUserType" runat="server" AutoPostBack="true" CssClass="NormalText" RepeatDirection="Horizontal">
<asp:ListItem Text="Adcomp" Value="Adcomp" ></asp:ListItem>
<asp:ListItem Text="Admin" Value="Admin"></asp:ListItem>
<asp:ListItem Text="User" Value="User"></asp:ListItem>                            
</asp:RadioButtonList>

On Certain condition i am changing its selection as :

RdoBtnUserType.SelectedItem.Text = rst.GetValue("UserType")

rst.GetValue("UserType") has string "Adcomp"

but its giving me error:

object not set to referance of the object.

when i do RdoBtnUserType.selectedValue = rst.GetValue("UserType")

Error :

'RdoBtnUserType' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

I am not understanding why this error is comming.

Plz help me.

2 Answers 2

1

You have to first select item from list like following

RdoBtnUserType.SelectedIndex = 0;

then you can write your following statement

RdoBtnUserType.SelectedItem.Text = rst.GetValue("UserType");
0
1

You are getting the error because there is nothing selected. and you are trying to access the SelecteItem property of the radio button list.

so either select an item and then try to change it or

RdoBtnUserType.SelectedIndex = RdoBtnUserType.Items.IndexOf(RdoBtnUserType.Items.FindByText(rst.GetValue("UserType")));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.