how to bind grid in mvc3 in asp.net

Posted by Meenakshi under ASP.NET on 5/5/2012 | Points: 10 | Views : 8232 | Status : [Member] | Replies : 3
hi,
i m new in mvc so i want to know how to bind gridview in mvc.
Thanks




Responses

Posted by: Kavi.Sirius on: 5/7/2012 [Member] Starter | Points: 25

Up
0
Down
HI,
In mvc u have a three layer

create the class in three layer:

presentation Layer:
In this layer call the Business Layer method
Business Layer:
In this layer call the dataaceess layer method
Dataaccess Layer:
It exectues the query.

All this methods are returns a value through Dataset

Example:

Presentation layer:

public partial class website1 : System.Web.UI.Page
{
Businesslayerclass objbusiness=new Businesslayerclass();

public void page_load()
{
}
public void Gridviewbinddata()
{
Dataset ds=new Dataset();
ds=objbusiness.GridviewBind();//call the businesslayer method
Gridview1.Datasource=ds;
Gridview1.DataBind();
}
}

BusinessLayer://class file


public class Businesslayerclass
{
Dataacesslayerclass objData=new Dataacesslayerclass();
public Dataset GridviewBind()
{
Dataset ds=new Dataset();
ds=objData.GridViewData();//call the dataaccesslayer method
return ds;
}
}

DataaacessLayer://class file

public class DataaacessLayer
{
sqlconnection con=new sqlconnection("database path");
sqlcommand cmd=new sqlcommand();
sqlDataAdapter da=new SqlDataAdapter();

public Dataset GridviewData()
{
Dataset ds=new Dataset();
con.open();
string StrQuery="select * from employeedetail";//query
ds=cmd.ExecuteNonQuery(StrQuery);
da.fill(ds);
return ds;//returns the dataset value to the business layer
}

i hope it helps you.........







Regards
Kavi.n

Meenakshi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: dhirenkaunar-15094 on: 5/7/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Meenakshi,

This can be archive archive in many ways :
There are some below different possibilities:
Server side grids:
The built-in WebGrid helper : http://weblogs.asp.net/andrebaltieri/archive/2010/11/01/asp-net-mvc-3-working-with-webgrid.aspx
MvcContrib Grid : http://mvccontrib.codeplex.com/wikipage?title=Grid
Telerik Grid : http://www.telerik.com/products/aspnet-mvc/grid.aspx

Client-Side grids:
jqGrid : http://www.trirand.com/blog/
YUI DataTable : http://developer.yahoo.com/yui/datatable/



http://weblogs.asp.net/andrebaltieri/archive/2010/11/01/asp-net-mvc-3-working-with-webgrid.aspx

Thanks & Rgards,
Dhiren Kumar Kaunar

Meenakshi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinay13mar on: 11/4/2012 [Member] Starter | Points: 25

Login to post response