How do fix the error The DataSourceID of 'DataGrid1' must be the ID of a control of type IDataSource. A control with ID 'SqlMedTable' could not be found.

How do you fix the error: The DataSourceID of 'DataGrid1' must be the ID of a control of type IDataSource.  A control with ID 'SqlMedTable' could not be found.
Here is the code.

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

MedicalClassLibrary.
Connection c = new MedicalClassLibrary.Connection();

c.GetMedicalTable();

DataGrid1.AutoGenerateColumns =
true;

DataGrid1.DataSource = c.DS;

InputDiv.Visible =
false;Label1.Visible = false;

txtRx.Focus();

}

}

Here is the class medhod:

public void GetMedicalTable()

{

string medTable = "SELECT * FROM tblMeds ORDER BY RX";using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["myConnection"]))

{

DS = new DataSet();

SqlDataAdapter da = new SqlDataAdapter(medTable, con);da.Fill(ds, "tblMeds");

}

}

0
bthumber
8/25/2007 11:15:21 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
1219 Views

Similar Articles

[PageSpeed] 55
Get it on Google Play
Get it on Apple App Store

Do you have the DataSourceID property on the DataGrid populated with "SqlMedTable" in markup like this:

<asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="SqlMedTable"></asp:DataGrid>

 

If you do, remove it.

Jason Conway

 


Jason Conway

MCP, MCTS, Certified SCRUM Master

asp.net blog
0
nicequy
8/26/2007 3:19:17 AM
Reply: