View
- @{
- ViewBag.Title = "Home Page";
- }
- "stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
- class="row">
- @Html.DropDownList("txt_city", null, "----Selected Country-----");
- >
- "btn" type="button" value="button" />
- >
Home Controller
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace dropdownlist.Controllers
- {
- public class HomeController : Controller
- {
- data_access_layer.db dblayer = new data_access_layer.db();
- public ActionResult Index()
- {
- city_bind();
- return View();
- }
- public void city_bind()
- {
- DataSet ds = dblayer.Get_Country();
- List
countrylist = new List (); - foreach (DataRow dr in ds.Tables[0].Rows)
- {
- countrylist.Add(new SelectListItem { Text = dr["city"].ToString(), Value = dr["city"].ToString() });
- }
- ViewBag.txt_city = countrylist;
- }
- public JsonResult a_add(string city)
- {
- DataSet ds = dblayer.Get_A_Add(city);
- List
statelist = new List (); - foreach (DataRow dr in ds.Tables[0].Rows)
- {
- statelist.Add(new SelectListItem { Text = dr["address2"].ToString(), Value = dr["address2"].ToString() });
- }
- return Json(statelist, JsonRequestBehavior.AllowGet);
- }
- public JsonResult b_add(string add)
- {
- DataSet ds = dblayer.Get_B_Add(add);
- List
citylist = new List (); - foreach (DataRow dr in ds.Tables[0].Rows)
- {
- citylist.Add(new SelectListItem { Text = dr["add1"].ToString(), Value = dr["add1"].ToString() });
- }
- return Json(citylist, JsonRequestBehavior.AllowGet);
- }
- public ActionResult About()
- {
- ViewBag.Message = "Your application description page.";
- return View();
- }
- public ActionResult Contact()
- {
- ViewBag.Message = "Your contact page.";
- return View();
- }
- }
- }
DB Layer
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- namespace dropdownlist.data_access_layer
- {
- public class db
- {
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
- //Get Country
- public DataSet Get_Country()
- {
- SqlCommand com = new SqlCommand("select distinct(city) as city from vehicle", con);
- SqlDataAdapter da = new SqlDataAdapter(com);
- DataSet ds = new DataSet();
- da.Fill(ds);
- return ds;
- }
- //Get Address
- public DataSet Get_A_Add(string city)
- {
- SqlCommand com = new SqlCommand("select distinct(a_address) as address2 from vehicle where city='"+city+"'", con);
- SqlDataAdapter da = new SqlDataAdapter(com);
- DataSet ds = new DataSet();
- da.Fill(ds);
- return ds;
- }
- //Get Address
- public DataSet Get_B_Add(string add)
- {
- SqlCommand com = new SqlCommand("select distinct(b_address) as add1 from vehicle where a_address='"+add+"'", con);
- SqlDataAdapter da = new SqlDataAdapter(com);
- DataSet ds = new DataSet();
- da.Fill(ds);
- return ds;
- }
- }
- }

I am tired Please help.
thanks
Mursaleen HassanPosted May 3, 2018, 1:41 PM
Rafnas T PPosted May 3, 2018, 1:37 PM
Mursaleen HassanPosted May 3, 2018, 1:34 PM
Amit GuptaPosted May 3, 2018, 12:51 PM