I have one radio buttonlist.Now i've to make visible the textbox,label based on radiobuttonlist selection.Here i attached my code.But can't make visible,hide the label,textboxes.Can anyone help me to solve this. Help me guys..
protected void rblReport_SelectedIndexChanged(object sender, EventArgs e)
{
if (rblReport.SelectedIndex == 1)
{
lblDate.Visible = true;
txtDate.Visible = true;
lblWeek.Visible = false;
txtWeek.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
else if (rblReport.SelectedIndex == 2)
{
lblWeek.Visible = true;
txtWeek.Visible = true;
lblDate.Visible = false;
txtDate.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
else if (rblReport.SelectedIndex == 3)
{
lblMonth.Visible = true;
ddlMonth.Visible = true;
lblWeek.Visible = false;
txtWeek.Visible = false;
txtDate.Visible = false;
txtDate.Visible = false;
}
}

Sunny SharmaPosted Jun 5, 2013, 6:27 AM
Have it here:
In ASPX Page
----------------------------------
onselectedindexchanged="rblReport_SelectedIndexChanged" AutoPostBack="true">
------------------------------------
In Code Behind Page:
------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
lblDate.Visible = false;
txtDate.Visible = false;
lblWeek.Visible = false;
txtWeek.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
protected void rblReport_SelectedIndexChanged(object sender, EventArgs e)
{
if (rblReport.SelectedIndex == 0)
{
lblDate.Visible = true;
txtDate.Visible = true;
lblWeek.Visible = false;
txtWeek.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
else if (rblReport.SelectedIndex == 1)
{
lblWeek.Visible = true;
txtWeek.Visible = true;
lblDate.Visible = false;
txtDate.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
else if (rblReport.SelectedIndex == 2)
{
lblMonth.Visible = true;
ddlMonth.Visible = true;
lblWeek.Visible = false;
txtWeek.Visible = false;
txtDate.Visible = false;
txtDate.Visible = false;
}
}
-----------------------------------------------------
Also, As an Alternate I've attached a sample working app. Refer to this for any clarification.
Thanks.
Kavi sujaPosted Jun 5, 2013, 7:26 AM
Pankaj PandeyPosted Jun 5, 2013, 6:42 AM
Format="MM/dd/yyyy">
.cs code...
Kavi sujaPosted Jun 5, 2013, 6:21 AM
Kavi sujaPosted Jun 5, 2013, 6:18 AM
Sunny SharmaPosted Jun 5, 2013, 6:16 AM
-------------------------------
Protected void Page_Load(....)
{
lblDate.Visible = false;
txtDate.Visible = false;
lblWeek.Visible = false;
txtWeek.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
-----------------------------------------------
Ravikumar GPosted Jun 5, 2013, 6:15 AM
Kavi sujaPosted Jun 5, 2013, 6:10 AM
Sunny SharmaPosted Jun 5, 2013, 6:09 AM
I see two errors in your code.
First one is you missed to include AutoPostBack="true" for "rblReport". You should add it.
------------------------------------------
------------------------------------------
Second, in your code behind page, you're accessing the Selectedindex Property for SelectIndex 1,2 & 3 but in your case the maximum selected Index would be two, I mean it starts with zero (0) i.e.: 0,1 & 2.
Do these modifications and it will work. OK & Tested solution.
Don't forget to accept this as answer if it helps.
Happy Coding :)
Thanks
Pankaj PandeyPosted Jun 5, 2013, 6:04 AM
replace your
By