Example of gridview binding

Hello Friends,

Today i want to show you how to bind gridview? I have created one simple example of gridview binding.
To create example i have used VS 2010 and Adventures database.

First create one web site/web application and create one page. Paste below code in your aspx page.


Now, in .cs file use following code to bind grid view.

                DBM.SqlCommandEx sqlCmd = new DBM.SqlCommandEx(
                        "SELECT TOP 10 Person.BusinessEntityID, FirstName, LastName, AddressLine1, City, PostalCode" +
                        " FROM Person.Person" +
                        " INNER JOIN Person.BusinessEntity on BusinessEntity.BusinessEntityID = Person.BusinessEntityID" +
                        " INNER JOIN Person.BusinessEntityAddress on BusinessEntityAddress.AddressID = BusinessEntity.BusinessEntityID" +
                        " INNER JOIN Person.Address on Address.AddressID = BusinessEntityAddress.AddressID" +
                        " ORDER BY FirstName");

                gvData.DataSource = sqlCmd.GetDataTable();
            catch (Exception ex)
                throw ex;

Now, you are ready. Hope it will help to beginner to bind data grid.
I am attaching example and other needed file with this article.
Download it from here GridViewExample.rar

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>