I need to total the responses from several radio button lists from a survey to another page, how can I code this? The responses are yes or no for each set of rbl's. I couldn't get a screenshot of the survey to load on here. Below is code that I started
but I don't think it is right. I'm thinking I will need individual if, else statements for each radio button list but not sure how to do this so it will add the total number of yes or no for each response for say a two week period. Any help will be greatly
appreciated.
//User defined method to calculate the survey results
private void DisplaySurveyResults()
{
if (lblTrainerOnTime = checked)
{
You can iterate through radiobutton list like this and get value for each radio button in that list,
for (int i=0; i<rbList1.Items.Count; i++) {
if (rbList1.Items[i].Selected)
//your code if radio button is selected
else
//your code if radio button is not selected
}
Pratik Galoria,
Software Engineer,
iGATE Global Solutions.
well am not gettin your question, but if you asking what should be here for "unchecked" then no need to write anything, as "else" part will be executed automatically if the radio button is not selected.
Pratik Galoria,
Software Engineer,
iGATE Global Solutions.
As pratik_galoria answered, No need to give condition again in else part. If it is not selected, else part will work.
And about your question, I think you want the result of each radiobutton on next page.right?
If so, you can keep each result in a public bit array and can transfer to next page suing Session.
Check whether a Yes button of one question is selected, if Yes put arrayname[index]=1 (no else part) if No button is selected arrayname[index]=0. Assign each question's answer in different index like arrayname[0],arrayname[1] etc and pass that value.
I hope for all questions you have yes/no answers only. If not, use pratik_galoria's first answer code to get the value
You need not use the array here (Sorry, first I thought you want all results seperately). Since you want the total of response of the radio button list, use a variable 'count' in your page and increase the count for each of your positive result
You are correct, I need each result seperatley. These are the survey rbl's which have a yes or no response. I need to add up each repsonse seperatley and keep a running total. I have no idea how to even begin to code this. The survey is on one web
page named CustomerSurvey and I need the results to display on another web page named SurveyComplete. I tried to insert a couple screenshots to help out but couldn't figure how to do that on here. If you could just code how to start and maybe the first two
rbl's along with what code would go on each page to make this work that would be greatly appreciated. I will post for Pratik also, I’m sure between the two of you I can get this set up and working properly.
You are correct, I need each result seperatley. These are the survey rbl's which have a yes or no response. I need to add up each repsonse seperatley and keep a running total. I have no idea how to even begin to code this. The survey is on one web page
named CustomerSurvey and I need the results to display on another web page named SurveyComplete. I tried to insert a couple screenshots to help out but couldn't figure how to do that on here. If you could just code how to start and maybe the first two rbl's
along with what code would go on each page to make this work that would be greatly appreciated. I will post for Pratik also, I’m sure between the two of you I can get this set up and working properly.
string[] _response = new string[10]; //here 10 is say number of questions
int i = 0;
foreach (RadioButton rb in rblTrainerOnTime.Items)
{
if(rb.Selected)
_response[i] = "yes";
else
_response[i] = "no";
i++;
}
foreach (RadioButton rb in rblTrainKnowledge.Items)
{
if(rb.Selected)
_response[i] = "yes";
else
_response[i] = "no";
i++;
}
// similarly for all upto rblClassJustRight //
// _response[0] will contain answer of your first question, _response[1] is answer of second an so on
// after that you can pass it to other page using session like this
Session["Response"] = _response;
//in other page you can retrieve those answer like this
string[] _response = (string[])Session["Response"];
Pratik Galoria,
Software Engineer,
iGATE Global Solutions.
Patrik, thank you for your help, the code looks like what I need, but I cannot get it right. I think I am placing it in the wrong block and also confusing myself with the new and old code. I think it would be easier for me to show you what I have rather
than try to explain it. I will paste the code for the survey.aspx.cs page and the SurveyComplete.aspx.cs page so you can have a better idea of where I'm messing up. I'm sorry the code is long mainly from the old commented out code which I don't think I will
need doing it your way.
public partial class Customer_CustomerSurvey : System.Web.UI.Page
{
private Survey svySurvey;
//clear the radio buttons from previous survey
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Page.Form.DefaultButton = btnSubmitSurvey.UniqueID;
txtComments.Text = "";
}
}
//User defined method to enable/disable controls on the survey form
//bool (enable) could be any name I wanted it to be, its just a variable name
private void EnableControls(bool enable)
{
lblHeading.Enabled = enable;
lblSurveyType.Enabled = enable;
rbIndividualSession.Enabled = enable;
rbClassSession.Enabled = enable;
lblTrainerOnTime.Enabled = enable;
rblTrainerOnTime.Enabled = enable;
lblKnowledge.Enabled = enable;
rblTrainKnowledge.Enabled = enable;
lblRecommend.Enabled = enable;
rblTrainRecommend.Enabled = enable;
lblIndividualTraining.Enabled = enable;
rblIndivSessionFun.Enabled = enable;
lblClassTraining.Enabled = enable;
rblClassFun.Enabled = enable;
lblClassHard.Enabled = enable;
rblClassHard.Enabled = enable;
lblEasy.Enabled = enable;
rblClassEasy.Enabled = enable;
lblJustRight.Enabled = enable;
rblClassJustRight.Enabled = enable;
lblComments.Enabled = enable;
btnSubmitSurvey.Enabled = enable;
}
foreach (RadioButton rb in rblTrainerOnTime.Items)
{
if (rb.Checked)//// had to change to checked, Selected was not accepted
_response[i] = "yes";
else
_response[i] = "no";
i++;
}
foreach (RadioButton rb in rblTrainKnowledge.Items)
{
if (rb.Checked)
_response[i] = "yes";
else
_response[i] = "no";
i++;
}
//THIS BLOCK OF CODE WAS THE ORIGINAL, I WON'T NEED THIS IF I DO IT YOUR WAY WILL I??
//if (rblTrainerOnTime.SelectedIndex != -1)
//{
// svySurvey.TrainerOnTime =
// Convert.ToInt32(rblTrainerOnTime.SelectedValue);
//}
Rag12
0 Points
8 Posts
I need to total radio button lists responses from a survey to another page, how can I code this?
Dec 04, 2012 02:43 AM|LINK
I need to total the responses from several radio button lists from a survey to another page, how can I code this? The responses are yes or no for each set of rbl's. I couldn't get a screenshot of the survey to load on here. Below is code that I started but I don't think it is right. I'm thinking I will need individual if, else statements for each radio button list but not sure how to do this so it will add the total number of yes or no for each response for say a two week period. Any help will be greatly appreciated.
//User defined method to calculate the survey results
private void DisplaySurveyResults()
{
if (lblTrainerOnTime = checked)
{
}
pratik_galor...
Participant
1483 Points
330 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 04, 2012 04:14 AM|LINK
You can iterate through radiobutton list like this and get value for each radio button in that list,
for (int i=0; i<rbList1.Items.Count; i++) { if (rbList1.Items[i].Selected) //your code if radio button is selected else //your code if radio button is not selected }Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
Rag12
0 Points
8 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 04, 2012 04:32 AM|LINK
count ++}
(rblTrainerOnTime.Items[i]. ???unchecked{
count++
}
Thanks
pratik_galor...
Participant
1483 Points
330 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 04, 2012 05:04 AM|LINK
well am not gettin your question, but if you asking what should be here for "unchecked" then no need to write anything, as "else" part will be executed automatically if the radio button is not selected.
Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
ishq
Member
256 Points
76 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 04, 2012 08:59 AM|LINK
As pratik_galoria answered, No need to give condition again in else part. If it is not selected, else part will work.
And about your question, I think you want the result of each radiobutton on next page.right?
If so, you can keep each result in a public bit array and can transfer to next page suing Session.
Check whether a Yes button of one question is selected, if Yes put arrayname[index]=1 (no else part) if No button is selected arrayname[index]=0. Assign each question's answer in different index like arrayname[0],arrayname[1] etc and pass that value.
I hope for all questions you have yes/no answers only. If not, use pratik_galoria's first answer code to get the value
Lathika Morthodi
ishq
Member
256 Points
76 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 04, 2012 10:48 AM|LINK
You need not use the array here (Sorry, first I thought you want all results seperately). Since you want the total of response of the radio button list, use a variable 'count' in your page and increase the count for each of your positive result
Lathika Morthodi
Rag12
0 Points
8 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 05, 2012 01:30 AM|LINK
You are correct, I need each result seperatley. These are the survey rbl's which have a yes or no response. I need to add up each repsonse seperatley and keep a running total. I have no idea how to even begin to code this. The survey is on one web page named CustomerSurvey and I need the results to display on another web page named SurveyComplete. I tried to insert a couple screenshots to help out but couldn't figure how to do that on here. If you could just code how to start and maybe the first two rbl's along with what code would go on each page to make this work that would be greatly appreciated. I will post for Pratik also, I’m sure between the two of you I can get this set up and working properly.
<asp:RadioButtonList ID="rblTrainerOnTime"
<asp:RadioButtonList ID="rblTrainKnowledge"
<asp:RadioButtonList ID="rblTrainRecommend"
<asp:RadioButtonList ID="rblIndivSessionFun"
<asp:RadioButtonList ID="rblClassFun"
<asp:RadioButtonList ID="rblClassHard"
<asp:RadioButtonList ID="rblClassEasy"
<asp:RadioButtonList ID="rblClassJustRight"
Rag12
0 Points
8 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 05, 2012 01:31 AM|LINK
You are correct, I need each result seperatley. These are the survey rbl's which have a yes or no response. I need to add up each repsonse seperatley and keep a running total. I have no idea how to even begin to code this. The survey is on one web page named CustomerSurvey and I need the results to display on another web page named SurveyComplete. I tried to insert a couple screenshots to help out but couldn't figure how to do that on here. If you could just code how to start and maybe the first two rbl's along with what code would go on each page to make this work that would be greatly appreciated. I will post for Pratik also, I’m sure between the two of you I can get this set up and working properly.
<asp:RadioButtonList ID="rblTrainerOnTime"
<asp:RadioButtonList ID="rblTrainKnowledge"
<asp:RadioButtonList ID="rblTrainRecommend"
<asp:RadioButtonList ID="rblIndivSessionFun"
<asp:RadioButtonList ID="rblClassFun"
<asp:RadioButtonList ID="rblClassHard"
<asp:RadioButtonList ID="rblClassEasy"
<asp:RadioButtonList ID="rblClassJustRight"
pratik_galor...
Participant
1483 Points
330 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 05, 2012 09:25 AM|LINK
do like this in your page_load(),
string[] _response = new string[10]; //here 10 is say number of questions int i = 0; foreach (RadioButton rb in rblTrainerOnTime.Items) { if(rb.Selected) _response[i] = "yes"; else _response[i] = "no"; i++; } foreach (RadioButton rb in rblTrainKnowledge.Items) { if(rb.Selected) _response[i] = "yes"; else _response[i] = "no"; i++; } // similarly for all upto rblClassJustRight // // _response[0] will contain answer of your first question, _response[1] is answer of second an so on // after that you can pass it to other page using session like this Session["Response"] = _response; //in other page you can retrieve those answer like this string[] _response = (string[])Session["Response"];Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
Rag12
0 Points
8 Posts
Re: I need to total radio button lists responses from a survey to another page, how can I code th...
Dec 05, 2012 01:02 PM|LINK
Patrik, thank you for your help, the code looks like what I need, but I cannot get it right. I think I am placing it in the wrong block and also confusing myself with the new and old code. I think it would be easier for me to show you what I have rather than try to explain it. I will paste the code for the survey.aspx.cs page and the SurveyComplete.aspx.cs page so you can have a better idea of where I'm messing up. I'm sorry the code is long mainly from the old commented out code which I don't think I will need doing it your way.
public partial class Customer_CustomerSurvey : System.Web.UI.Page
{
private Survey svySurvey;
//clear the radio buttons from previous survey
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Page.Form.DefaultButton = btnSubmitSurvey.UniqueID;
txtComments.Text = "";
}
}
//User defined method to enable/disable controls on the survey form
//bool (enable) could be any name I wanted it to be, its just a variable name
private void EnableControls(bool enable)
{
lblHeading.Enabled = enable;
lblSurveyType.Enabled = enable;
rbIndividualSession.Enabled = enable;
rbClassSession.Enabled = enable;
lblTrainerOnTime.Enabled = enable;
rblTrainerOnTime.Enabled = enable;
lblKnowledge.Enabled = enable;
rblTrainKnowledge.Enabled = enable;
lblRecommend.Enabled = enable;
rblTrainRecommend.Enabled = enable;
lblIndividualTraining.Enabled = enable;
rblIndivSessionFun.Enabled = enable;
lblClassTraining.Enabled = enable;
rblClassFun.Enabled = enable;
lblClassHard.Enabled = enable;
rblClassHard.Enabled = enable;
lblEasy.Enabled = enable;
rblClassEasy.Enabled = enable;
lblJustRight.Enabled = enable;
rblClassJustRight.Enabled = enable;
lblComments.Enabled = enable;
btnSubmitSurvey.Enabled = enable;
}
//Only allow input for the type of survey choosen
protected void rbIndividualSession_CheckedChanged(object sender, EventArgs e)
{
if (rbIndividualSession.Checked)
{
rblTrainerOnTime.Enabled = true;
rblTrainKnowledge.Enabled = true;
rblTrainRecommend.Enabled = true;
rblIndivSessionFun.Enabled = true;
rblClassFun.Enabled = false;
rblClassHard.Enabled = false;
rblClassEasy.Enabled = false;
rblClassJustRight.Enabled = false;
}
else
{
rblTrainerOnTime.Enabled = true;
rblTrainKnowledge.Enabled = true;
rblTrainRecommend.Enabled = true;
rblIndivSessionFun.Enabled = false;
rblClassFun.Enabled = true;
rblClassHard.Enabled = true;
rblClassEasy.Enabled = true;
rblClassJustRight.Enabled = true;
}
}
protected void btnSubmitSurvey_Click(object sender, EventArgs e)
{
if (IsValid)
{
svySurvey = new Survey();
if (Session["soSurvey"] != null)
{
Session.Remove("soSurvey");
}
Session.Add("soSurvey", svySurvey);
Session.Add["Response"] = _response; /////ERROR HERE
svySurvey.ClientID = Convert.ToInt32(txtClientID.Text);
string[] _response = new string[10];
int i = 0;
foreach (RadioButton rb in rblTrainerOnTime.Items)
{
if (rb.Checked)//// had to change to checked, Selected was not accepted
_response[i] = "yes";
else
_response[i] = "no";
i++;
}
foreach (RadioButton rb in rblTrainKnowledge.Items)
{
if (rb.Checked)
_response[i] = "yes";
else
_response[i] = "no";
i++;
}
//THIS BLOCK OF CODE WAS THE ORIGINAL, I WON'T NEED THIS IF I DO IT YOUR WAY WILL I??
//if (rblTrainerOnTime.SelectedIndex != -1)
//{
// svySurvey.TrainerOnTime =
// Convert.ToInt32(rblTrainerOnTime.SelectedValue);
//}
//if (rblTrainKnowledge.SelectedIndex != -1)
//{
// svySurvey.TrainKnowledge =
// Convert.ToInt32(rblTrainKnowledge.SelectedValue);
//}
//if (rblTrainRecommend.SelectedIndex != -1)
//{
// svySurvey.TrainRecommend =
// Convert.ToInt32(rblTrainRecommend.SelectedValue);
//}
//if (rblIndivSessionFun.SelectedIndex != -1)
//{
// svySurvey.IndivSessionFun =
// Convert.ToInt32(rblIndivSessionFun.SelectedValue);
//}
//if (rblClassFun.SelectedIndex != -1)
//{
// svySurvey.ClassFun =
// Convert.ToInt32(rblClassFun.SelectedValue);
//}
//if (rblClassHard.SelectedIndex != -1)
//{
// svySurvey.ClassHard =
// Convert.ToInt32(rblClassHard.SelectedValue);
//}
//if (rblClassEasy.SelectedIndex != -1)
//{
// svySurvey.ClassEasy =
// Convert.ToInt32(rblClassEasy.SelectedValue);
//}
//if (rblClassJustRight.SelectedIndex != -1)
//{
// svySurvey.ClassJustRight =
// Convert.ToInt32(rblClassJustRight.SelectedValue);
//}
svySurvey.Comments = txtComments.Text;
Session["Response"] = _response; ////NOT SURE ABOUT USING THIS AND THE NEXT LINE
Response.Redirect("SurveyComplete.aspx");
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
rbIndividualSession.Checked = false;
rbClassSession.Checked = false;
rblTrainerOnTime.ClearSelection();
rblTrainKnowledge.ClearSelection();
rblTrainRecommend.ClearSelection();
rblIndivSessionFun.ClearSelection();
rblClassFun.ClearSelection();
rblClassHard.ClearSelection();
rblClassEasy.ClearSelection();
rblClassJustRight.ClearSelection();
//txtComments.Clear(); //???????????? don't know why this doesn't work
}
}
___________________________________________________________________________________________
public partial class Customer_SurveyComplete : System.Web.UI.Page
{
Survey svSurvey;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["soSurvey"] == null)
{
lblTrainerOnTime.Text = "";//row 1
lblTrainerLate.Text = "";//row 1
Label1.Text = ""; //row 2 yes
Label2.Text = ""; //row 2 no
Label3.Text = ""; //row 3 yes
Label4.Text = ""; //row 3 no etc...(no, yes)repeated down the list to Label14
Label5.Text = "";
Label6.Text = "";
Label7.Text = "";
Label8.Text = "";
Label9.Text = "";
Label10.Text = "";
Label11.Text = "";
Label12.Text = "";
Label13.Text = "";
Label14.Text = "";
}
else
{
string[] _response = (string[])Session["Response"];
// DisplaySurveyResponse();
}
}
//User Defined Method to Display Survey Response
//private void DisplaySurveyResponse()
//{
// svSurvey = (Survey)Session["soSurvey"];
// switch (svSurvey.TrainerOnTime)
// {
// case 1:
// lblTrainerOnTime.Text = "Yes";
// break;
// case 2:
// lblTrainerOnTime.Text = "No";
// break;
// }
// switch (svSurvey.TrainKnowledge)
// {
// case 1:
// lblKnowledge.Text = "Yes";
// break;
// case 2:
// lblKnowledge.Text = "No";
// break;
// }
// switch (svSurvey.TrainRecommend)
// {
// case 1:
// lblRecommend.Text = "Yes";
// break;
// case 2:
// lblRecommend.Text = "No";
// break;
// }
// switch (svSurvey.IndivSessionFun)
// {
// case 1:
// lblIndSessionsFun.Text = "Yes";
// break;
// case 2:
// lblIndSessionsFun.Text = "No";
// break;
// }
// switch (svSurvey.ClassFun)
// {
// case 1:
// lblClassFun.Text = "Yes";
// break;
// case 2:
// lblClassFun.Text = "No";
// break;
// }
// switch (svSurvey.ClassHard)
// {
// case 1:
// lblClassHard.Text = "Yes";
// break;
// case 2:
// lblClassHard.Text = "No";
// break;
// }
// switch (svSurvey.ClassJustRight)
// {
// case 1:
// lblJustRight.Text = "Yes";
// break;
// case 2:
// lblJustRight.Text = "No";
// break;
}
Session.Remove("soContact");
Session.Remove("soSurvey");
}
}