asp.net mvc - how to bind datatable to webgrid using MVC? -


this first post. me. how bind datatable webgrid? code:

sqlconnection con = new sqlconnection(cs); sqlcommand cmd = new sqlcommand("select * candidate", con); sqldataadapter da = new sqldataadapter(cmd); datatable dt = new datatable(); da.fill(dt); return view(dt); 

i want bind datatable webgrid..help me...

this best solution found :) hope can you:

sqlconnection con = new sqlconnection(cs); sqlcommand cmd = new sqlcommand("select * candidate", con);  datatable dt = new datatable(); sqldataadapter = new sqldataadapter(cmd) a.fill(dt);  var result = new list<dynamic>(); foreach (datarow row in dt.rows) {     var obj = (idictionary<string, object>)new expandoobject();     foreach (datacolumn col in dt.columns)     {         obj.add(col.columnname, row[col.columnname]);     }     result.add(obj); }  webgrid grid = new webgrid(model, canpage: true, rowsperpage: 15); 

then in view can use:

@grid.gethtml(htmlattributes: new { id = "emptable" },             tablestyle: "table table-striped table-hover",             headerstyle: "header",             alternatingrowstyle: "alt",             selectedrowstyle: "select",             columns: grid.columns(                 grid.column("col1name", "column title"),                 grid.column("col2name", "column2 title")      )) 

where grid webgrid grid variable.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -