c# - Trying to bind GridView from Linq -
so have dataset populated xml file, i'm trying populate gridview using linq. gridview rendering empty. here code-behind...
protected void page_load(object sender, eventargs e) { linqsamples samples = new linqsamples(gvnumbers, this.page); samples.datasetlinq40(); } private class linqsamples { private dataset testds; private gridview _gv; private page _pg; public linqsamples(gridview gv, page pg) { testds = testhelper.createtestdataset(pg); _gv = gv; _pg = pg; } public void datasetlinq40() { var numbers = testds.tables["numbers"].asenumerable(); //var numbergroups = n in numbers // group n n.field<int>("number") % 5 g // select new { remainder = g.key, numbers = g }; //var justnums = n in numbers // select n; _gv.datasource = justnums; _gv.databind(); } } internal static dataset createtestdataset(page pg) { dataset ds = new dataset(); // customers table ds.tables.add(createnumberstable()); ds.acceptchanges(); return ds; } private static datatable createnumberstable() { int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; datatable table = new datatable("numbers"); table.columns.add("number", typeof(int)); foreach (int n in numbers) { table.rows.add(new object[] { n }); } return table; }
...and .aspx page...
<asp:gridview id="gvnumbers" runat="server" autogeneratecolumns="false"> </asp:gridview>
neither numbergroups nor justnums works, both result in empty gridview.
Comments
Post a Comment