
Hi,
In MVC 3, you have a WebGrid control where you can display the data.
Here is the code...
Write the following code in your ViewPage....
@{
ViewBag.Title = "Purchased";
}
<h2>
Purchased</h2>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LIST OF PURCHASED</title>
<style type="text/css">
.gridTable
{
margin: 5px;
padding: 10px;
border: 1px #c8c8c8 solid;
border-collapse: collapse;
min-width: 550px;
background-color: #fff;
color: #fff;
}
.gridHead th
{
font-weight: bold;
background-color: #000000;
color: #fff;
padding: 10px;
}
.gridHead a:link, .gridHead a:visited, .gridHead a:active, .gridHead a:hover
{
color: #FFBBFF;
}
.gridHead a:hover
{
text-decoration: underline;
}
.gridTable tr.gridAltRow
{
background-color: #efeeef;
}
.gridTable tr:hover
{
background-color: #FFCCCC;
}
.gridAltRow td
{
padding: 10px;
margin: 5px;
color: #333;
}
.gridRow td
{
padding: 10px;
color: #333;
}
.gridFooter td
{
padding: 10px;
background-color: #c7d1d6;
color: #999;
font-size: 12pt;
text-align: center;
}
.gridFooter a
{
font-weight: bold;
color: #333;
border: 1px #333 solid;
}
.</style>
</head>
<body>
@*<script src="../../Scripts/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>*@
<div id="divmsg" style="color: Green; font-weight: bold">
</div>
<br />
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.NextPrevious);
@grid.GetHtml(tableStyle: "gridTable",
htmlAttributes: new { id = "DataTable" },
headerStyle: "gridHead",
footerStyle: "gridFooter",
rowStyle: "gridRow",
alternatingRowStyle: "gridAltRow",
columns: grid.Columns(
grid.Column("EmpID"),
grid.Column("EmpName"),
grid.Column("Designstion"),
grid.Column("Salary"),
grid.Column("DeptNo")
));
}
</body>
</html>
Then, in the controller write the following code..............
public ActionResult Purchased()
{
var emply= from p in db.TableName
select new
{
EmpID= p.EmpID,
EmpName= p.EmpName,
Designation= p.Designation,
Salary= p.Salary,
DeptNo= p.DeptNo,
};
return View(emply.ToList());
}
That's it........
Mark as answer if satisfied............
Regards,
Shree M.
Kavya Shree Mandapalli
ramuvalmiki07-22001, if this helps please login to Mark As Answer. | Alert Moderator