Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button list

Status
Not open for further replies.

tek2002

Programmer
Aug 21, 2001
67
0
0
US
working with a webform that has a radio button list ... when one of the buttons is clicked, i would like a certain action taken without having to use a submit button.

does anyone have any code on this or can u point me to where i can find some.

for simplicity sake, lets say that you want a label populated with 'you have picked button #1' if the first radio button is clicked and so on....

thanks for any help on this.
 
Enable the AutoPostBack property on the control and get a reference on the clicked item in code behind in SelectedIndexChanged event handler:
Code:
<asp:RadioButtonList id=RadioButtonList1 runat=&quot;server&quot; AutoPostBack=True>
 <asp:ListItem Value=1 Selected=True>Option 1</asp:ListItem>
 <asp:ListItem Value=2>Option 2</asp:ListItem>
 <asp:ListItem Value=3>Option 3</asp:ListItem>
</asp:RadioButtonList>
.............
private void InitializeComponent()
{    
 this.RadioButtonList1.SelectedIndexChanged += new System.EventHandler(this.RadioButtonList1_SelectedIndexChanged);
 this.Load += new System.EventHandler(this.Page_Load);
}

private void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
  ListItem clickedItem = RadioButtonList1.SelectedItem;
  int selValue = (int)clickedItem.Value;
  string seltheText = clickedItem.Text;
}
 
Thanks so much - i made some changes b/c using vb.net - works great though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top