protected void Page_Load(object sender, EventArgs e) { RestServiceUrl s = new RestServiceUrl(); string url = s.url + "search_name/cvr"; string category = null, city = null; WebRequest request = WebRequest.Create(url) as HttpWebRequest; WebResponse response = null; String Xml; // get response using (response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); Xml = reader.ReadToEnd(); } StringReader _sr = new StringReader(Xml); XmlTextReader _xtr = new XmlTextReader(_sr); _xtr.XmlResolver = null; _xtr.WhitespaceHandling = WhitespaceHandling.None; /* _xtr.Read(); * _xtr.Read(); * _xtr.Read(); */ int count = 0; while (_xtr.Read()) { if (_xtr.Name.ToString().Equals("Institutions_search_name")) { count++; } if (_xtr.Name.ToString().Equals("Category")) { category = _xtr.ReadString(); } if (_xtr.Name.ToString().Equals("City")) { city = _xtr.ReadString(); } } count = count / 2; Label1.Text = category + " " + city; }
protected void Page_Load(object sender, EventArgs e) { // Retreiving paramters from the query string string search_name = Request.QueryString["name"].ToString(); string search_cat = Request.QueryString["cat"].ToString(); string search_loc = Request.QueryString["loc"].ToString(); List <SearchResults> l = new List <SearchResults>(); RestServiceUrl s = new RestServiceUrl(); string url = s.url + "search_name/" + search_name; string category = null, city = null; WebRequest request = WebRequest.Create(url) as HttpWebRequest; WebResponse response = null; String Xml; // get response using (response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); Xml = reader.ReadToEnd(); } StringReader _sr = new StringReader(Xml); XmlTextReader _xtr = new XmlTextReader(_sr); _xtr.XmlResolver = null; _xtr.WhitespaceHandling = WhitespaceHandling.None; int count = 0; while (_xtr.Read()) { if (_xtr.Name.ToString().Equals("Institutions_search_name")) { count++; } } count = count / 2; StringReader _sr1 = new StringReader(Xml); XmlTextReader _xtr1 = new XmlTextReader(_sr1); _xtr1.XmlResolver = null; _xtr1.WhitespaceHandling = WhitespaceHandling.None; for (int i = 0; i < count; i++) { SearchResults sres = new SearchResults(); _xtr1.Read(); // array of institutions _xtr1.Read(); // institutions_search_name // Category _xtr1.Read(); sres.category = _xtr1.ReadString(); //City _xtr1.Read(); sres.city = _xtr1.ReadString(); // Institute Logo _xtr1.Read(); sres.ins_logo = _xtr1.ReadString(); //Inst_name _xtr1.Read(); sres.ins_name = _xtr1.ReadString(); //Institute_id _xtr1.Read(); sres.ins_id = "InstituteHome.aspx?id=" + _xtr1.ReadString(); //State _xtr1.Read(); sres.state = _xtr1.ReadString(); //street _xtr1.Read(); //isVerified _xtr1.Read(); //no of likes _xtr1.Read(); _xtr1.Read(); _xtr1.Read(); _xtr1.Read(); _xtr1.Read(); sres.no_of_likes = _xtr1.ReadString(); l.Add(sres); } GridView1.DataSource = l; GridView1.DataBind(); }
protected void search_image_Click(object sender, ImageClickEventArgs e) { string search_name = TextBox1.Text; if (search_name.Equals(null) || search_name.Equals("")) { search_name = "null"; } string search_cat = DropDownList1.SelectedItem.Value.ToString(); if (search_cat.Equals(null)) { search_cat = "null"; } string search_loc = TextBox2.Text; if (search_loc.Equals(null) || search_loc.Equals("")) { search_loc = "null"; } Label7.Text = search_name + " " + search_cat + " " + search_loc; // Response.Redirect("Search_results.aspx?name=" + search_name+"&cat="+search_cat+"&loc="+search_loc); // Rest Service URL RestServiceUrl s = new RestServiceUrl(); if (search_name.Equals("null") || search_name.Equals(null)) { if (search_cat.Equals("") || search_cat.Equals(null)) { Label7.Text = "Please select a category to search"; } else { if (search_loc.Equals("") || search_loc.Equals(null)) { Label7.Text = "Please enter a location to search"; } else { url = s.url + "search_cat_loc/" + search_cat + "," + search_loc; } } } else { if (search_cat.Equals("null") || search_cat.Equals(null)) { // Category not there if (search_loc.Equals("null") || search_loc.Equals(null)) { //Category not there and location not there - > only name url = s.url + "search_name/" + search_name; } else { // Name and location url = s.url + "search_name_loc/" + search_name + "," + search_loc; } } else { // Category there if (search_loc.Equals("null") || search_loc.Equals(null)) { //Category there but no location -> cat and name url = s.url + "search_name_cat/" + search_name + "," + search_cat; } else { // all three url = s.url + "search_name_cat_loc/" + search_name + "," + search_cat + "," + search_loc; } } } List <SearchResults> l = new List <SearchResults>(); string category = null, city = null; WebRequest request = WebRequest.Create(url) as HttpWebRequest; WebResponse response = null; String Xml; // get response using (response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); Xml = reader.ReadToEnd(); } StringReader _sr = new StringReader(Xml); XmlTextReader _xtr = new XmlTextReader(_sr); _xtr.XmlResolver = null; _xtr.WhitespaceHandling = WhitespaceHandling.None; int count = 0; while (_xtr.Read()) { if (_xtr.Name.ToString().Equals("Institutions_search_name")) { count++; } } count = count / 2; if (count == 0) { Label7.Visible = true; Label7.Text = "No Results Found ! Please try again"; GridView1.Visible = false; } else { StringReader _sr1 = new StringReader(Xml); XmlTextReader _xtr1 = new XmlTextReader(_sr1); _xtr1.XmlResolver = null; _xtr1.WhitespaceHandling = WhitespaceHandling.None; for (int i = 0; i < count; i++) { SearchResults sres = new SearchResults(); _xtr1.Read(); // array of institutions _xtr1.Read(); // institutions_search_name // Category _xtr1.Read(); sres.category = _xtr1.ReadString(); //City _xtr1.Read(); sres.city = _xtr1.ReadString(); // Institute Logo _xtr1.Read(); sres.ins_logo = _xtr1.ReadString(); //Inst_name _xtr1.Read(); sres.ins_name = _xtr1.ReadString(); //Institute_id _xtr1.Read(); sres.ins_id = "InstituteHome.aspx?id=" + _xtr1.ReadString(); //State _xtr1.Read(); sres.state = _xtr1.ReadString(); //street _xtr1.Read(); //isVerified _xtr1.Read(); //no of likes _xtr1.Read(); _xtr1.Read(); _xtr1.Read(); _xtr1.Read(); _xtr1.Read(); sres.no_of_likes = _xtr1.ReadString(); l.Add(sres); } Label7.Visible = false; GridView1.Visible = true; GridView1.DataSource = l; GridView1.DataBind(); } }