I have a class that queries the db and returns a datatable. I want to have a method that takes the datatable and loads the page with the data. I don't want to write most of the codes on the page.cs
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VikramPosted Jun 23, 2010, 7:16 AM
What do you mean by loads the page. I assume you want to fill a gridView. If this the requirement then just write a following method in any other Class:
public void FillGridView(ref GridView gvList)
{
DataTable dt = new DataTable();
// Write code here to get DataTable from the DataBase.
gvList.DataSource = dt;
gvList.DataBind();
}
And in the page load or any other Event simply Call above method by passing Gridview as a parameter.
obj.FillGridView(ref GridView1);
By this way you can seperate the code from .aspx.
Regards,
VIkram