Forum Moderators: open

Message Too Old, No Replies

how to set and retrive the radiobutton list in usercontrol

usercontrol list

         

priteshgupta

6:06 am on Nov 25, 2008 (gmt 0)

10+ Year Member



hi..
I have designed a usercontrol containing a radiobuttonlist control.I am using this usercontrol on different page.I want io retrive the radiobutton selected index.,but I don't know how to do that.
I tried by define property on usercontrol page

public property GetSelectedValue() as string
Get
return radiobtn.selectedindex
end get
set (value as string)
radiobtn.selectedindex=value
end set

but in this case I don't know how to set that value(I can't use
usercontrol.GetSelectedValue=something as i do not know value of something)

do i need to add some event handler?

plz help me out there or suggest me is there better to way to design quiz

Response

2:20 pm on Nov 25, 2008 (gmt 0)

10+ Year Member



The Radiobutton control does not have a SelectedIndex property. When working with just a RadioButton, test the Checked property.

To work with groups of RadioButtons and SelectedIndex, it is necessary to use the RadioButtonList control (<asp:radiobuttonlist>).

[edited by: eelixduppy at 5:50 am (utc) on Nov. 26, 2008]
[edit reason] disabled smileys [/edit]

priteshgupta

5:28 am on Nov 26, 2008 (gmt 0)

10+ Year Member



hi..
I had clearly mentioned that i am using radiobuttonlist control.
problem is about how to retrive values od dynamic control from usercontrol

Response

3:17 pm on Nov 26, 2008 (gmt 0)

10+ Year Member



I had clearly mentioned that i am using radiobuttonlist control.

So you did. My apologies. I should drink more coffee before I make replies. :)

After rereading your post. Here is your code with the changes.


public property GetSelectedValue() as string
Get
return myRadioButtonList.SelectedValue
end get
set (value as string)
_SelValue = value
end set

Without knowing exactly what you are doing. I assume you have a variable length list of radiobuttons and may want to select a particular item. The Get is simple, the Set requires more work.

Once the member var _SelValue is set. Use this value to set the Checked property as you create the radiobuttons. Hope this helps.

-Response