.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DataGrid >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Binding of gridview from Datatable

Posted By:Gowthammanju       Posted Date: July 30, 2011    Points: 40    Category: DataGrid    URL: http://www.dotnetspark.com  

These code explains about binding of gridview by passing the values from datatable.
 

Here it is as


 string Provider = "connectionstring";
        SqlConnection con = new SqlConnection(Provider);
        SqlCommand cmd = new SqlCommand("SELECT * FROM tablename", con);
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        
        DataTable CustomerTable = new DataTable();// calling data table
        adapter.Fill(CustomerTable);//filling in to datatable

        Grid.DataSource = CustomerTable;
        Grid.DataBind();



where Grid is the gridview name.


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend