Reputation: 1653
I have a Check Box in my asp page. Once I clicked on it, the page display (visible = true
) a table id='xx'. This table has two rows. A Dropdown and a Lable.
<table>
<tr>
<td colspan='2'>
<asp:CheckBox runat="server" ID="CheckBox1" Text="check" Checked="true" AutoPostBack="true"
OnCheckedChanged="CheckBox1_CheckedChanged" />
<table id='xx' runat="server">
<tr>
<td colspan='2'>
Student Information :
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Select Student name :"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Width="200px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Select Student name :"></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
this.xx.Visible = CheckBox1.Checked;
}
Once user change the selected drop Down value The label value should change.
ex: If user select 'City' in Drop down the Label2.text = Dropdown.selectedvalue
.
I have used AutoPostBack="true"
for all Check Box control and Drop down while postback.
Issue scenario:
Please help me to display change value On label2 once user has changed the value on Drop down without non-visibling the table.
Thank you.
Upvotes: 0
Views: 1107
Reputation: 1295
Use this
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostback)
{
this.xx.Visible = CheckBox1.Checked;
}
}
Upvotes: 0
Reputation: 12576
try this. you need to AutoPostBack=True in DropDownList.
aspx:
<table id='xx' runat="server">
<tr>
<td colspan='2'>
Student Information :
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Select Student name :"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Width="200px"
AutoPostBack="true" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="city1" Text="city1"></asp:ListItem>
<asp:ListItem Value="city2" Text="city2"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Select Student name :"></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
this.xx.Visible = CheckBox1.Checked;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label2.Text = this.DropDownList1.Text;
}
Upvotes: 0
Reputation: 16144
Do this on your Page_Load Event:
this.xx.Visible = CheckBox1.Checked;
Upvotes: 0