Sunday, 2 February 2014

How we will show data at the runtime help of RadioButtonList SelectIndexChanged Event

put this code inside of body tag

<form id="form1" runat="server">
<div>
<h1>Example</h1>
<table>
<tr><td>Name:</td><td><asp:TextBox ID="name" runat ="server"></asp:TextBox></td></tr>
<tr><td>Age:</td><td><asp:TextBox ID="age" runat="server"></asp:TextBox></td></tr>
<tr><td valign="top">Are you married:</td><td><asp:RadioButtonList ID="RadioButtonList1"
runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" >
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
</asp:RadioButtonList>
<asp:Panel ID="p1" runat="server">
Marriage date:&nbsp; <asp:TextBox ID="date" runat="server"></asp:TextBox><br />
No. of Children:<asp:TextBox ID="child" runat="server"></asp:TextBox>
</asp:Panel>


</td>


</tr>
</table>

</div>
</form>

 c# Code


protected void Page_Load(object sender, EventArgs e)
{
p1.Visible = false;
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedItem.Text == "Yes")
p1.Visible = true;
else
p1.Visible = false;
}

No comments:

Post a Comment