Hi I am getting only the last value from the database in the webgrid. I have used foreach to get all the value from the database and binded it to the webgrid but it is showing only the last value in the webgrid . Please guide me
var listobject = list ;
foreach (var m in ViewBag.Model)
{
var list = new[]
{
new { Name = m.Name, Genre =m.Genre }
};
listobject = list;
}
WebGrid studentGrid = new WebGrid();
studentGrid.Bind(listobject, autoSortAndPage: false, rowCount: 3);
%>
<%= studentGrid.GetHtml(columns:
new WebGridColumn[]
{
studentGrid.Column("Name", "name"),
studentGrid.Column("Genre", "Genre"),
})
%>