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 SharmaRank #223 · 11.1K reputationPosted Jun 5, 2013, 2:27 AM EDT
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.
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 5, 2013, 2:04 AM EDT
replace your
By
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 5, 2013, 2:09 AM EDT
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
Kavi sujaRank #6,237 · 272 reputationPosted Jun 5, 2013, 2:10 AM EDT
Ravikumar G178 reputationPosted Jun 5, 2013, 2:15 AM EDT
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 5, 2013, 2:16 AM EDT
-------------------------------
Protected void Page_Load(....)
{
lblDate.Visible = false;
txtDate.Visible = false;
lblWeek.Visible = false;
txtWeek.Visible = false;
lblMonth.Visible = false;
ddlMonth.Visible = false;
}
-----------------------------------------------
Kavi sujaRank #6,237 · 272 reputationPosted Jun 5, 2013, 2:18 AM EDT
Kavi sujaRank #6,237 · 272 reputationPosted Jun 5, 2013, 2:21 AM EDT
Pankaj PandeyRank #642 · 3.7K reputationPosted Jun 5, 2013, 2:42 AM EDT
Format="MM/dd/yyyy">
.cs code...
Kavi sujaRank #6,237 · 272 reputationPosted Jun 5, 2013, 3:26 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts