-1

Sir, Im doing a project in asp.net 4.0 with c#.I my project i want to display datas from the database to the grid view using Data Source Control. But while doing it im getting an eror called "The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'System.Web.UI.WebControls.SqlDataSource' could not be found.". My code is also givren below.

SqlCommand cmd = new SqlCommand("SPS_LeaveBalanceReport_DSO", Connect.con());
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ReportMonth", SqlDbType.NVarChar).Value =
    SelectMonthDropDown.SelectedValue.ToString();
cmd.Parameters.Add("@ReportYear", SqlDbType.NVarChar).Value =
    SelectYearDropDown.SelectedItem.Text.ToString();            

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "tab");    

GridView1.DataSourceID = SqlDataSource1.ToString();
GridView1.DataBind();

Please help me with error.,thanks In Advance.,

Graham Clark
  • 12,886
  • 8
  • 50
  • 82

2 Answers2

1

change

GridView1.DataSourceID = SqlDataSource1.ToString();

to

GridView1.DataSourceID = SqlDataSource1.ID;
Graham Clark
  • 12,886
  • 8
  • 50
  • 82
0

The problem is no where in your cod ejust replace the line

GridView1.DataSourceID = SqlDataSource1.ToString();

with

GridView1.DataSource=ds;

it will work

Devjosh
  • 6,450
  • 4
  • 39
  • 61
  • Hai Sir., Thank u for the Code. But it is still not working. The Error now im getting is "The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'System.Data.DataSet' could not be found." – user177777 May 05 '11 at 11:00
  • change the property from DataSourceId to DataSource – Devjosh May 05 '11 at 11:06