Both DataSource and DataSourceID are defined on 'GridView2'. Remove one definition

asp.net, c#, gridview

Solution

 DataSourceID="ds"

This is not needed when you are adding datasource from code behind.

Problem

I am trying to reload a gridview upon date selected from calendar. I know there are duplicate questions on SO but their answers did not work for me ``` protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Label1.Text = Calendar1.SelectedDate.ToShortDateString(); DataSet ds = dlObj.FillDataSet("SELECT top 5 [DName], [bloodGroup], [dateDonated] FROM [tblDonors] ORDER BY [dateDonated] DESC ", "tblDonors"); GridView2.DataSource = ds; GridView2.DataBind(); } ``` And the method FillDataSet() is this ``` public DataSet FillDataSet(string q, string tableName) { DataSet ds = new DataSet(); try { SqlDataAdapter da = new SqlDataAdapter(q, thisConnection); da.Fill(ds, tableName); return ds; } catch (Exception) { return ds; } } ``` When I click any date, this error occurs ``` Both DataSource and DataSourceID are defined on 'GridView2'. Remove one definition. ```

Original source