Mursaleen Hassan

Mursaleen Hassan

  • NA
  • 22
  • 4.1k

Spacing Text could not be match in SQL Server

May 3 2018 11:57 AM
View
 
  1. @{  
  2.     ViewBag.Title = "Home Page";  
  3. }  
  4. <script src="~/Scripts/jquery-1.10.2.min.js"></script>  
  5. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">  
  6. <script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>  
  7. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>  
  8.   
  9. <script>  
  10.   
  11.     $(document).ready(function () {  
  12.           
  13.           
  14.         $("#txt_city").change(function () {  
  15.   
  16.             var id = $(this).val();  
  17.              
  18.             $("#txta_address").empty();  
  19.             $.get("a_add", { city: id }, function myfunction(data) {  
  20.                 var v = "<option>---Select----</option>";  
  21.                 $.each(data, function (i, v1) {  
  22.                     v += "<option value=" + v1.Value + ">" + v1.Text + "</option>";  
  23.   
  24.                 });  
  25.                 $("#txta_address").html(v);  
  26.             });  
  27.         });  
  28.         $("#btn").on('click'function () {  
  29.   
  30.             var id = $("#txta_address").val();  
  31.             $("#txtb_address").empty();  
  32.             $.get("b_add", { add: id }, function myfunction(data) {  
  33.                 var v = "<option>---Select----</option>";  
  34.                 $.each(data, function (i, v1) {  
  35.                     v += "<option value=" + v1.Value + ">" + v1.Text + "</option>";  
  36.   
  37.                 });  
  38.                 $("#txtb_address").html(v);  
  39.             });  
  40.         });  
  41.   
  42.          
  43.     });  
  44.       
  45.   
  46. </script>  
  47. <div class="row">  
  48.     <div>  
  49.         @Html.DropDownList("txt_city"null"----Selected Country-----");  
  50.     </div>  
  51.     <div>  
  52.         <select id="txta_address"></select>  
  53.         <input id="btn" type="button" value="button" />  
  54.     </div>  
  55.     <div>  
  56.         <select id="txtb_address"></select>  
  57.     </div>  
  58. </div>  
 
 Home Controller
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Mvc;  
  7.   
  8. namespace dropdownlist.Controllers  
  9. {  
  10.     public class HomeController : Controller  
  11.     {  
  12.         data_access_layer.db dblayer = new data_access_layer.db();  
  13.   
  14.         public ActionResult Index()  
  15.         {  
  16.             city_bind();  
  17.             return View();  
  18.         }  
  19.   
  20.         public void city_bind()  
  21.         {  
  22.             DataSet ds = dblayer.Get_Country();  
  23.   
  24.             List<SelectListItem> countrylist = new List<SelectListItem>();  
  25.             foreach (DataRow dr in ds.Tables[0].Rows)  
  26.             {  
  27.                 countrylist.Add(new SelectListItem { Text = dr["city"].ToString(), Value = dr["city"].ToString() });  
  28.   
  29.             }  
  30.             ViewBag.txt_city = countrylist;  
  31.   
  32.         }  
  33.   
  34.         public JsonResult a_add(string city)  
  35.         {  
  36.             DataSet ds = dblayer.Get_A_Add(city);  
  37.             List<SelectListItem> statelist = new List<SelectListItem>();  
  38.             foreach (DataRow dr in ds.Tables[0].Rows)  
  39.             {  
  40.                 statelist.Add(new SelectListItem { Text = dr["address2"].ToString(), Value = dr["address2"].ToString() });  
  41.             }  
  42.             return Json(statelist, JsonRequestBehavior.AllowGet);  
  43.   
  44.         }  
  45.   
  46.         public JsonResult b_add(string add)  
  47.         {  
  48.             DataSet ds = dblayer.Get_B_Add(add);  
  49.             List<SelectListItem> citylist = new List<SelectListItem>();  
  50.             foreach (DataRow dr in ds.Tables[0].Rows)  
  51.             {  
  52.                 citylist.Add(new SelectListItem { Text = dr["add1"].ToString(), Value = dr["add1"].ToString() });  
  53.             }  
  54.             return Json(citylist, JsonRequestBehavior.AllowGet);  
  55.   
  56.         }  
  57.   
  58.   
  59.         public ActionResult About()  
  60.         {  
  61.             ViewBag.Message = "Your application description page.";  
  62.   
  63.             return View();  
  64.         }  
  65.   
  66.         public ActionResult Contact()  
  67.         {  
  68.             ViewBag.Message = "Your contact page.";  
  69.   
  70.             return View();  
  71.         }  
  72.     }  
  73. }  
 
DB Layer
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. using System.Linq;  
  7. using System.Web;  
  8.   
  9. namespace dropdownlist.data_access_layer  
  10. {  
  11.     public class db  
  12.     {  
  13.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);  
  14.           
  15.         //Get Country  
  16.         public DataSet Get_Country()  
  17.         {  
  18.             SqlCommand com = new SqlCommand("select distinct(city) as city from vehicle", con);  
  19.             SqlDataAdapter da = new SqlDataAdapter(com);  
  20.             DataSet ds = new DataSet();  
  21.             da.Fill(ds);  
  22.             return ds;  
  23.   
  24.         }  
  25.         //Get Address  
  26.         public DataSet Get_A_Add(string city)  
  27.         {  
  28.             SqlCommand com = new SqlCommand("select distinct(a_address) as address2 from vehicle where city='"+city+"'", con);  
  29.             SqlDataAdapter da = new SqlDataAdapter(com);  
  30.             DataSet ds = new DataSet();  
  31.             da.Fill(ds);  
  32.             return ds;  
  33.   
  34.         }  
  35.   
  36.         //Get Address  
  37.         public DataSet Get_B_Add(string add)  
  38.         {  
  39.             SqlCommand com = new SqlCommand("select distinct(b_address) as add1 from vehicle where a_address='"+add+"'", con);  
  40.             SqlDataAdapter da = new SqlDataAdapter(com);  
  41.             DataSet ds = new DataSet();  
  42.             da.Fill(ds);  
  43.             return ds;  
  44.   
  45.         }  
  46.     }  
  47. }  
SQl Server Database
 
 
 
 
I am tired Please help.
thanks 
 

Answers (4)