Click here to Skip to main content
15,917,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datatable in my user control, gridview is in aspx page i want to bind the details in datatable to gridview.
Posted
Updated 3-Nov-10 21:14pm
v2

In your usercontrol you can reference the gridview in the page by using the FindControl method, after that it's standard databinding:

C#
var gridView = this.Page.FindControl("ID OF GRIDVIEW HERE") as GridView;
gridView.DataSource = myDataTable;
gridView.DataBind();
 
Share this answer
 
Comments
MathewPV 4-Nov-10 3:24am    
Thank you Jim for your valuable reply this will work when "myDataTable" is in the aspx page but for me the DataTable is in a user control and i want to bind that DataTable to aspx gridview
Hiren solanki 4-Nov-10 3:31am    
Datatable is not a physical visual control that you can put it in ascx page. I think.
set the datatable as public in your webusercontrol.
//web user control
public static DataTable dt()
{
//your code.
}
//aspx page.
GridView1.DataSource =WebUserControl.dt();
GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900