Web technology

web developers learning site

Archive for the month “April, 2013”

How to load grid using ajax load in asp.net

Controller code

[GridAction]
public ActionResult GetStudentInfo(string roll)
{
List<Student> lstStudent = new List<Student>();
int rollNumber = Convert.ToInt32(roll);

using (db_practiseEntities dbContext = new db_practiseEntities())
{
lstStudent = (from s in dbContext.Student
where s.Roll == rollNumber
select s).ToList();
}
return View(new GridModel<Student> { Data = lstStudent });

}

view code

@(Html.Telerik().Grid<Student>()
.Name(“gdStudentList”)
.DataKeys(keys => keys.Add(k => k.Roll))
.Columns(column =>
{
column.Bound(s => s.Id);
column.Bound(s => s.StudentName);
column.Bound(s => s.Roll);
column.Bound(s => s.DepartmentName);
column.Bound(s => s.Email);
})
.DataBinding(dbBindings => dbBindings.Ajax().Select(“GetStudentInfo”, “Home”))
)

js code

$(“#Student”).change(function () {
var params = {
roll: this.value
};
var grid = $(‘#gdStudentList’).data(“tGrid”);

grid.dataSource._data = [];
grid.ajaxRequest(params);
});

 

 

How to show a Database Driven drop down in Asp.net(MVC3)

Controller code

List<Department> lstDpt = new List<Department>();

using(db_practiseEntities dbContext = new db_practiseEntities())
{
lstDpt = dbContext.Department.ToList();
}

ViewBag.lstDepartment = lstDpt;
return View();

view for dropdown

@Html.DropDownList(“DepartmentName”, new SelectList(@ViewBag.lstDepartment, “DName”, “DName”))

 

How to show Telerick grid in asp.net

For controller Code

List<StudentInformation> lstStudent = new List<StudentInformation>();

using(db_practiseEntities dbContext = new db_practiseEntities())
{
var v = from st in dbContext.tblStudent
join sinfo in dbContext.tblStudenInfo
on st.Id equals sinfo.s_id
select new StudentInformation {
Id = st.Id,
Name = st.Name,
Roll = st.Roll,
Email = st.Email,
Address = sinfo.Address,
Mobile = sinfo.Mobile
};
lstStudent = v.ToList();
}

ViewBag.studnetInfo = lstStudent;
return View();

View Page code

List<StudentInformation> lstStudent = new List<StudentInformation>();
lstStudent = (List<StudentInformation>)ViewBag.studnetInfo;

@(Html.Telerik().Grid(lstStudent)
.Name(“gvStudentList”)
.DataKeys(keys => keys.Add(k => k.Id))
.Columns(column => {
column.Bound(s => s.Id);
column.Bound(s => s.Name);
column.Bound(s => s.Roll);
column.Bound(s => s.Email);
column.Bound(s => s.Address);
column.Bound(s => s.Mobile);
})
.Scrollable(scroll=>scroll.Height(200))
.Selectable()
.Pageable(PageData => PageData.PageSize(3))
)

 

 

Post Navigation