I have updated the code and now getting the error below:
Server Error in '/QuestLocal' Application.
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Source Error:
Line 21: for (int j = 0; (j <= rbl.Items.Count); j++)
Line 22: {
Line 23: if ((rbl.Items[j].Value == "4")) Line 24: {
Line 25: if (Request.Cookies["Q1"] != null)
Works perfectly now obeying all conditions! Weldone Amal, and thank you very, very much. I do not see anything I have done to the code attached. Congratulations once more.
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 29, 2012 10:14 AM|LINK
I have updated the code and now getting the error below:
Server Error in '/QuestLocal' Application.
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Source Error:
Line 21: for (int j = 0; (j <= rbl.Items.Count); j++) Line 22: { Line 23: if ((rbl.Items[j].Value == "4")) Line 24: { Line 25: if (Request.Cookies["Q1"] != null)Source File: c:\inetpub\wwwroot\QuestLocal\Q1.aspx.cs Line: 23
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button3_Click(object sender, EventArgs e) { foreach (DetailsViewRow gvr in DetailsView1.Rows) { if ((gvr.RowType == DataControlRowType.DataRow)) { RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("RadioButtonList1"))); for (int j = 0; (j <= rbl.Items.Count); j++) { if ((rbl.Items[j].Value == "4")) { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } else { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } } } } } } }AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 29, 2012 10:31 AM|LINK
try
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 29, 2012 11:02 AM|LINK
Changed as suggested,
for (int j = 0; j <= rbl.Items.Count-1; j++)
No error, but stuck in Q1. Doesn't move on when the button is clicked.
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 29, 2012 11:32 AM|LINK
you are stuck there because you haven't change the code as i told you !!!
if ((rbl.Items[j].Value == "4")) { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } } else { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } }make the else for the first if not the second
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 29, 2012 11:46 AM|LINK
Hi Amal, Attached is what I have done but still stuck. Kindly do the changes on the code for me.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button3_Click(object sender, EventArgs e) { foreach (DetailsViewRow gvr in DetailsView1.Rows) { if ((gvr.RowType == DataControlRowType.DataRow)) { RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("RadioButtonList1"))); for (int j = 0; j <= rbl.Items.Count-1; j++) { if ((rbl.Items[j].Value == "5")) { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } } else { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } } } } } }AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 29, 2012 11:58 AM|LINK
hey iam sorry maybe you should change this
if( rbl.selectedValue.toString () == "5")and no need for the for loop ,,, i missundertood you from the begining so the code will be withour the for loop as followsif ((rbl.selectValue.toString() == "5")) { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } } else { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } }asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 29, 2012 12:15 PM|LINK
No errors, but still stuck. See full code attached.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button3_Click(object sender, EventArgs e) { foreach (DetailsViewRow gvr in DetailsView1.Rows) { if ((gvr.RowType == DataControlRowType.DataRow)) { RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("RadioButtonList1"))); { if ((rbl.SelectedValue.ToString() == "5")) { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } } else { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } } } } } }AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 29, 2012 12:19 PM|LINK
can i see you aspx page please? and what do u mean its stuck ??
do u mean it always goes to q2 , you mean always the value is 5?
try to change from selectedValue to selectedText
asante_za
Member
16 Points
113 Posts
Re: Condition in Cookie
Apr 29, 2012 01:29 PM|LINK
Works perfectly now obeying all conditions! Weldone Amal, and thank you very, very much. I do not see anything I have done to the code attached. Congratulations once more.
protected void Button3_Click(object sender, EventArgs e) { foreach (DetailsViewRow gvr in DetailsView1.Rows) { if ((gvr.RowType == DataControlRowType.DataRow)) { RadioButtonList rbl = ((RadioButtonList)(gvr.FindControl("RadioButtonList1"))); { if ((rbl.SelectedValue.ToString() == "5")) { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q2.aspx"); } } else { if (Request.Cookies["Q1"] != null) { Response.Cookies["Q1"].Value = Label2.Text.ToString(); Response.Redirect("../QuestLocal/Q3.aspx"); } } } } } }AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Condition in Cookie
Apr 29, 2012 01:42 PM|LINK
thank you asante ,, that's my pleasure to help you :)