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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VikramRank #9,295 · 208 reputationPosted Jun 23, 2010, 3:16 AM EDT
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