This post will help you to loop through all the items of RadioButtonList and find out the selected value. There is a direct method also to find the selected value.
rdoWebsiteList.SelectedItem.ToString()
Loop Through RadioButtonList items and get seletec item Example:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ">
<script runat="server">
protected void btnGetSelected_Click(object sender, EventArgs e)
{
lblSelected.Text = "Your selected Radio button value is: <br>";
foreach (ListItem lst in rdoWebsiteList.Items)
{
if (lst.Selected == true)
{
lblSelected.Text += lst.Text ;
}
}
lblSelected.Text += "<br>Using Another method: " + rdoWebsiteList.SelectedItem.ToString();
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rdoWebsiteList" runat="server" >
<asp:ListItem>BharatPad.com</asp:ListItem>
<asp:ListItem>TestingWiz.com</asp:ListItem>
<asp:ListItem>SharePointBank.com</asp:ListItem>
<asp:ListItem>SoftwareTestingNet.com</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button ID="btnGetSelected" runat="server" Text="Get Selected Values" OnClick="btnGetSelected_Click" />
<br />
<asp:Label ID="lblSelected" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
0 comments:
Post a Comment