In this article I will sharing how to bind with GridView control with Database and without database using Data Table.
Bind GridView with Database
I have define the GridView in the Web Form (Presentation Layer) and from this I am calling the method defined in BLL class (Business Logic Layer)
Here I am calling the method from presentation layer which was defined in BLL class (Business Login Layer)
Calling the BindEmpData class from the Web Form.
Method in the BLL class and it is calling the other class in the Data Access Layer.
public static DataSet BindPlanData(int EmpId)
DataSet ds = new DataSet();
ds = Dsll. GetEmployeeInfo(EmpId);
Method defined in the DAL class
public static DataSet GetEmployeeInfo(int intEmpId)
int QType = 2;
using (SqlConnection oConnection = new SqlConnection(ApplicationConnectionString()))
SqlParameter parameters = new SqlParameter;
parameters = new SqlParameter(intEmpId, System.Data.SqlDbType.Int);
parameters.Value = intEmpId
ds = SqlHelper.ExecuteDataset(oConnection, CommandType.StoredProcedure, "mySP_GetEmployeeInfo", parameters);
catch (Exception ex)
throw new Exception(ex.Message + " GetEmployeeInfo", ex);
Bind GridView without Database using Data Table
DataTable dt = new DataTable();
dt.Rows.Add("10023", "Abdullah Khan", "882-2221");
dt.Rows.Add("11002", "Abulrehman Ali", "882-1132");
dt.Rows.Add("23211", "Asim Afzal", "KG", "882-4211");
grdvTest.DataSource = dt;
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs,
googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.
The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.