Click here to Skip to main content
15,888,239 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to get webgrid column values for each row on controller side in mvc or if want to get particular row and column value.


What I have tried:

var exceldata = Db.stus.ToList();
            WebGrid grid = new WebGrid(source: exceldata, canPage: false, canSort: false);
            var gridData = grid.GetHtml(
            columns: grid.Columns(
                            grid.Column("stu_id", "Id"),
                            grid.Column("Stu_name", "Name"),
                            grid.Column("class", "Class"),
                            grid.Column("roll", "Roll"),
                            grid.Column("email", "Email"),
                            grid.Column("phone", "Phone")
                            )).ToString();
            int columns = gridData.Length;
foreach(var item in gridData)
{
int id=????
string class=???
string name=???
string email=???
}
Posted
Comments
Richard Deeming 28-Feb-18 12:46pm    
Don't try to read the data from the grid; read the data from the data source instead (exceldata).
MukeshKamboj28 1-Mar-18 0:48am    
how to read from datasource in mvc?pls explain little bit
Richard Deeming 1-Mar-18 8:59am    
You have a collection called exceldata, which is what you're using to generate the grid. Loop through that collection:
foreach (var item in exceldata)
{
    int id = item.Id;
    ...
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900