namespace MvcAppVehicleSystem.Controllers
{
public class HomeController : Controller
{
VehicleSysHireEntities2 _db;
public HomeController()
{
_db = new VehicleSysHireEntities2();
}
public ActionResult Index()
{
var query = _db.VehicleRentTypes.ToList();
var query2 = _db.VehicleCategories.ToList();
var model = new Models.SelectViewModel
{
CategoryList = query2,
RentTypeList = query
};
return View(model);
}
[HttpPost]
public ActionResult Index(VehicleMasterModel role)
{
VehicleMaster currentVehicle = new VehicleMaster();
currentVehicle.Brand = role.Brand;
currentVehicle.Category = role.Category;
currentVehicle.Model = role.Model;
currentVehicle.Color = role.Color;
currentVehicle.NoOfYear = role.NoOfYear;
currentVehicle.RentType = role.RentType;
_db.AddToVehicleMasters(currentVehicle);
_db.SaveChanges();
if (currentVehicle.ID > 0)
{
VehicleFacility currentfacility = new VehicleFacility();
currentfacility.VehicleMasterID = currentVehicle.ID;
currentfacility.HasABS = role.HasABS;
currentfacility.HasAirCon = role.HasAirCon;
currentfacility.HasCTX = role.HasCTX;
_db.AddToVehicleFacilities(currentfacility);
_db.SaveChanges();
}
return Json(true);
}
public ActionResult About()
{
var query = _db.VehicleRentTypes.ToList();
var query2 = _db.VehicleCategories.ToList();
var model = new Models.SelectViewModel
{
CategoryList = query2,
RentTypeList = query
};
return View(model);
}
[HttpPost]
public ActionResult About(VehicleMaster role)
{
List objList = (from m in _db.VehicleMasters select m).ToList();
return Json(objList);
}
[HttpPost]
public ActionResult AboutResult(VehicleMasterModel role)
{
var objList = (from m in _db.VehicleMasters
where m.RentType == role.RentType
select new VehicleMasterModel()
{
Brand = m.Brand,
Model = m.Model
}).ToList();
return Json(objList, JsonRequestBehavior.AllowGet);
}
}
}
Model-> SelectViewModel
public class SelectViewModel
{
public List CategoryList { get; set; }
public List RentTypeList { get; set; }
public VehicleFacility currentvehiclefacility { get; set; }
public VehicleMaster currentvehiclemaster { get; set; }
}
Model-> VehicleCategoryModel
public class VehicleCategoryModel
{
public int ID { get; set; }
public string Category { get; set; }
public List VehicleCategoryList { get; set; }
}
Model-> VehicleFacilityModel
public class VehicleFacilityModel
{
public List VehicleMasterList { get; set; }
public int ID { get; set; }
public bool HasAirCon { get; set; }
public bool HasABS { get; set; }
public bool HasCTX { get; set; }
public int VehicleMasterID { get; set; }
}
Model-> VehicleMasterModel
public class VehicleMasterModel
{
public int ID { get; set; }
public int Category { get; set; }
public string Brand { get; set; }
public string Model { get; set; }
public string Color { get; set; }
public int NoOfYear { get; set; }
public int RentType { get; set; }
public bool HasAirCon { get; set; }
public bool HasABS { get; set; }
public bool HasCTX { get; set; }
public int VehicleMasterID { get; set; }
}
Model-> VehicleRentTypeModel
public class VehicleRentTypeModel
{
public int ID { get; set; }
public string RentType { get; set; }
public List VehicleRetTypeList { get; set; }
}
Home->Index
@{
ViewBag.Title = "Home Page";
}
@ViewBag.Message
@model MvcAppVehicleSystem.Models.SelectViewModel
Type
@Html.DropDownList("ddlType", new SelectList(Model.RentTypeList, "ID", "RentType"), "Select Type", new { required = "required" })
Category
@Html.DropDownList("ddlCategory", new SelectList(Model.CategoryList, "ID", "Category"), "Select Category", new { required = "required" })
Model
@Html.DropDownList("ddlModel", new[] {
new SelectListItem() {Text = "Audi",Value = "Audi"},
new SelectListItem() {Text = "Maruti",Value = "Maruti" },
new SelectListItem() {Text = "Suzuki",Value = "Suzuki" }
}, "Choose model", new { required = "required" })
No of year
@Html.DropDownList("ddlNoofYear", new[] {
new SelectListItem() {Text = "2010",Value = "2010"},
new SelectListItem() {Text = "2011",Value = "2 011" },
new SelectListItem() {Text = "2012",Value = "2012" },
new SelectListItem() {Text = "2013",Value = "2013" }
}, "Choose year", new { required = "required" })
Gridview header checkbox select and deselect all rows using client side JavaScript and server side C#
In this article, I will show you how to add checkbox in gridview header
template then select and deselect all rows in gridview using clients
side JavaScript and server side as well.
Introduction
Adding checkbox in gridview header template and select/deselect all
rows is a common requirement in most of the asp.net projects and
frequently asked questions also. Here I will explain how to add checkbox
in header template of gridview and select/deselect all rows using
client side javascript and server side code.
Add Checkbox in Gridview header template
Create the asp.net project and drag the gridview control then format as likes below.
Using HeaderTemplate of gridview I had added checkbox and also added in Itemtemplate of same column.
Select and deselect using Client side
I’m loading the few sample employee records in gridview to
select/deselect all rows. Below javascript CheckAllEmp function will do
select and deselect when check and uncheck in header checkbox. Call this
function in gridview headertemplate, checkbox onclick event as shown
above.
Above javascript code will get gridview client id and loop the each
row and get the checkbox id which is available in itemTemplate and make
it select/deselect rows. This is the one of the way using client side
script.
Select and deselect using Server side
Same functionality we can able to do with server side also. To do this make the changes in HeaderTemplate as like below.
Make it autopostback as true and create OnCheckedChanged event in
checkbox and add the below code in chkboxSelectAll_CheckedChanged event
in code behind part.
Above checked changed event will get the header checkbox id and if
header checkbox is checked then find all rows checkbox id and make it
all select else deselect all rows