TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mursaleen Hassan
NA
22
4.4k
Spacing Text could not be match in SQL Server
May 3 2018 11:57 AM
View
@{
ViewBag.Title =
"Home Page"
;
}
<script src=
"~/Scripts/jquery-1.10.2.min.js"
></script>
<link rel=
"stylesheet"
href=
"http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"
>
<script src=
"http://code.jquery.com/ui/1.11.0/jquery-ui.js"
></script>
<script type=
"text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
></script>
<script>
$(document).ready(
function
() {
$(
"#txt_city"
).change(
function
() {
var
id = $(
this
).val();
$(
"#txta_address"
).empty();
$.get(
"a_add"
, { city: id },
function
myfunction(data) {
var
v =
"<option>---Select----</option>"
;
$.each(data,
function
(i, v1) {
v +=
"<option value="
+ v1.Value +
">"
+ v1.Text +
"</option>"
;
});
$(
"#txta_address"
).html(v);
});
});
$(
"#btn"
).on(
'click'
,
function
() {
var
id = $(
"#txta_address"
).val();
$(
"#txtb_address"
).empty();
$.get(
"b_add"
, { add: id },
function
myfunction(data) {
var
v =
"<option>---Select----</option>"
;
$.each(data,
function
(i, v1) {
v +=
"<option value="
+ v1.Value +
">"
+ v1.Text +
"</option>"
;
});
$(
"#txtb_address"
).html(v);
});
});
});
</script>
<div
class
=
"row"
>
<div>
@Html.DropDownList(
"txt_city"
,
null
,
"----Selected Country-----"
);
</div>
<div>
<select id=
"txta_address"
></select>
<input id=
"btn"
type=
"button"
value=
"button"
/>
</div>
<div>
<select id=
"txtb_address"
></select>
</div>
</div>
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<SelectListItem> countrylist =
new
List<SelectListItem>();
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<SelectListItem> statelist =
new
List<SelectListItem>();
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<SelectListItem> citylist =
new
List<SelectListItem>();
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;
}
}
}
SQl Server Database
I am tired Please help.
thanks
Reply
Answers (
4
)
Web page content has to refreshed automatically
OTP Verify With Asp.Net MVC