[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

Request.QueryString producing corrupt value

Asked by ChefMaha in Programming for ASP.NET, C# Programming Language

Tags: ASP.NET, IE, none

I have a link that takes me to fooditems.aspx?Category="breakfast"

however, when I trace the code: Category = Request.QueryString["Category"].ToString();

I find that the resulting value of Category is: "\"breakfast\""

where could the problem be?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Web.Security;
using System.Configuration;
using User;
using Db;
 
namespace ChefMaha
{
	/// <summary>
	/// Summary description for fooditems.
	/// </summary>
	public class fooditems : System.Web.UI.Page
	{
		protected System.Data.OleDb.OleDbCommand FoodListOleDbCommand;
		protected System.Web.UI.WebControls.DataList FoodDataList;
		protected static System.Data.OleDb.OleDbConnection ChefMahaOleDbConn;
		protected static string ConnectionStr;
		protected static System.Data.OleDb.OleDbCommand FoodOleDbCommand;
		protected System.Web.UI.WebControls.DropDownList CategoryDropDownList;
		protected string ConnectionPhysicalPath;
		protected System.Data.OleDb.OleDbCommand CategoryOleDbCommand;
		protected static string SelectAllFromFood;
 
 
		private void Page_Load(object sender, System.EventArgs e)
		{
			
			if(!IsPostBack)
			{
				//set connection string
				ConnectionPhysicalPath = Server.MapPath("~/db/ChefMaha.mdb");
				ConnectionStr = ConfigurationSettings.AppSettings.Get("ConnectionString") + ConnectionPhysicalPath;
				SelectAllFromFood = FoodOleDbCommand.CommandText;
				
				ChefMahaOleDbConn = new OleDbConnection(ConnectionStr);
 
				LoadDropDownListWithData();
			}
 
			GetChosenCategory();
 
			LoadDataListWithData();
 
		}
 
		
		private void LoadDataListWithData()
		{
 
			if(ChefMahaOleDbConn.State.ToString() == "Closed")
			{
				ChefMahaOleDbConn.Open();
			}
							
			FoodOleDbCommand.Connection = ChefMahaOleDbConn;
 
			OleDbDataReader FoodDataReader = FoodOleDbCommand.ExecuteReader();
			FoodDataList.DataSource = (object) FoodDataReader;
			FoodDataList.DataBind();
				
			ChefMahaOleDbConn.Close();
		}
 
		/// <summary>
		/// gets the category chosen by the user
		/// </summary>
		private void GetChosenCategory()
		{
			string Category;
 
			try
			{
				Category = Request.QueryString["Category"].ToString();	
			}	
		
			catch(NullReferenceException)			
			{ 
				return;
			}
 
			ModifySelectedCategory(Category);
		}
 
 
		/// <summary>
		/// modifies the SQL statement of the menu grid according to the selected category
		/// </summary>
		/// <param name="SelectedCategory">the category selected by the user</param>
		private void ModifySelectedCategory(string SelectedCategory)
		{
			if(SelectedCategory == "All")
			{
				FoodOleDbCommand.CommandText = SelectAllFromFood;
			}
 
			else
 
			{
				string AppendedToSelectCmd = "WHERE FCtgEn = ";
 
				try
				{
					string NewValue = AppendedToSelectCmd + "'" + SelectedCategory + "'";
 
					FoodOleDbCommand.CommandText = SelectAllFromFood.Replace("ORDER BY FCtgEn", NewValue); 
				}
				catch(NullReferenceException)
				{
					foreach (Control c in Page.Controls)
					{
						c.Visible=false; 
					}
 
					Response.Write("An Error Occurred. Please refresh the Page.");
				}
			}
		
			LoadDataListWithData();
 
			if(CategoryDropDownList.SelectedValue != SelectedCategory)
			{
				try
				{
					CategoryDropDownList.SelectedValue = SelectedCategory;
				}
 
				catch(Exception ex)
				{
					for(int i=0; i<CategoryDropDownList.Items.Count; i++)
					{
						Response.Write(CategoryDropDownList.Items[i].Value);
					}
				}
			}
 
		} 
 
		
 
		/// <summary>
		/// loads the category drop down list with the categories from db
		/// </summary>
		private void LoadDropDownListWithData()
		{
 
				ChefMahaOleDbConn.Open();
			
 
			CategoryOleDbCommand.Connection = ChefMahaOleDbConn;
 
			OleDbDataReader CategoryDataReader = CategoryOleDbCommand.ExecuteReader();
		
			while(CategoryDataReader.Read())
			{
				string Category = CategoryDataReader.GetString(0);
				string CategoryEn = CategoryDataReader.GetString(1);
 
				ListItem CategoryListItem = new ListItem(Category, CategoryEn);
				CategoryDropDownList.Items.Add(CategoryListItem);
			}
 
			CategoryDataReader.Close();
 
			ChefMahaOleDbConn.Close();
		}
 
		private void CategoryDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
 
			ChefMahaOleDbConn.Open();
		
			ModifySelectedCategory(CategoryDropDownList.SelectedValue);
 
			ChefMahaOleDbConn.Close();
		}
 
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			FoodOleDbCommand = new System.Data.OleDb.OleDbCommand();
			this.CategoryOleDbCommand = new System.Data.OleDb.OleDbCommand();
			this.CategoryDropDownList.SelectedIndexChanged += new System.EventHandler(this.CategoryDropDownList_SelectedIndexChanged);
			// 
			// FoodOleDbCommand
			// 
			FoodOleDbCommand.CommandText = "SELECT FCtg,  FCtgEn, FName, FUnit, FUnitPrice, FDescr, FPhoto FROM FOOD ORDER BY" +
				" FCtgEn";
			// 
			// CategoryOleDbCommand
			// 
			this.CategoryOleDbCommand.CommandText = "SELECT DISTINCT FCtg , FCtgEn FROM FOOD;";
			this.Load += new System.EventHandler(this.Page_Load);
 
		}
		#endregion
 
		
	}
}
[+][-]09/02/08 10:53 PM, ID: 22374475Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming for ASP.NET, C# Programming Language
Tags: ASP.NET, IE, none
Sign Up Now!
Solution Provided By: Binuth
Participating Experts: 4
Solution Grade: A
 
[+][-]09/02/08 11:32 PM, ID: 22374598Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/08 12:37 AM, ID: 22374792Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/03/08 06:59 AM, ID: 22377237Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/08 08:43 AM, ID: 22378489Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/06/08 12:20 AM, ID: 22406401Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628