Sunday 2 February 2014

Use of Panel in Asp.Net

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Use of Panel</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="rd" runat="server" RepeatDirection="Horizontal" onselectedindexchanged="rd_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem>Student</asp:ListItem>
<asp:ListItem>Employee</asp:ListItem>
</asp:RadioButtonList>

<asp:Panel ID="p1" runat="server">
<table cellpadding="1" cellspacing="2">
<tr><td>Name</td><td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td></tr>
<tr><td>Address</td><td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td></tr>
<tr><td>Qualification</td><td><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td></tr>
<tr><td>Email</td><td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td></tr>
</table>
</asp:Panel>

<asp:Panel ID="p2" runat="server">
<table cellpadding="1" cellspacing="2">
<tr><td>Emp Name</td><td><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td></tr>
<tr><td>Address</td><td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td></tr>
<tr><td>Previous Job</td><td><asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td></tr>
<tr><td>Salary</td><td><asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></td></tr>
</table>
</asp:Panel>


</div>
</form>
</body>
</html>

 C# Code 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class panel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
p1.Visible = false;
p2.Visible = false;
}
protected void rd_SelectedIndexChanged(object sender, EventArgs e)
{

if (rd.SelectedItem.Text == "Student")
p1.Visible = true;


if (rd.SelectedItem.Text == "Employee")
p2.Visible = true;
}
}

No comments:

Post a Comment