Please refer this code.
Here i am popuplating two GridView with one Generic function.
Namespaces
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GridBind(this.gvCustomers, "Select CustomerId, ContactName, CompanyName from Customers");
this.GridBind(this.gvEmployees, "Select EmployeeId, FirstName, LastName from Employees");
}
}
public void GridBind(GridView gv, string query)
{
string strQuery = query;
DataTable dt = new DataTable();
string strCon = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strCon))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
gv.DataSource = dt;
gv.DataBind();
}
}
}
}