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

Remove a value from DataSourceID property.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.