i called a method and wrote the code there it throws an error of both datasource and datasource id shouldnot have the same name.
public void bindGridView()
{
ArrayList l=new ArrayList();
string strcon = ConfigurationManager.ConnectionStrings["connection"].ToString();
SqlConnection con = new SqlConnection(strcon);
con.Open();
string insertstmt="SELECT * FROM officemaster where deptoffcode='"+TextBox1.Text+"'";
SqlCommand cmd = new SqlCommand(insertstmt, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
l.Add(dr[0].ToString());
}
GridView.DataSource = l;
GridView.DataBind();
}
this was my code