I have a gridview that i want to fill with data from my linq to sql file.
I tried to create a function to fill a gridview with a string that its the table name.
InformitoDataContext db = new InformitoDataContext();
public void FillGridView(string Table, Control GridView)
{
var ds = from q
in db.Table //Error in db.Table: 'InformitoDataContext' does not contain a definition for 'Table'
select q;
(GridView as GridView).DataSource = ds;
(GridView as GridView).DataBind();
}
And it should be working like this:
public void Page_Load(object sender, EventArgs e)
{
Data.FillGridView("news", GridView1);
}
How can i solve this issue?
You may try using reflexion:
But this is not something I would recommend… you are linking objects to strings though linq to SQL is doing the exact contrary…
Well… I did not test the code, it may not compile… this is just to get the idea