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

Top 5 Contributors of the Month
Gaurav Pal

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;

where Grid is the gridview name.


Further Readings:


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