Reputation: 3452
I am getting an error for this c# code
if (radioAll.Checked)
{
SqlDataSource DataSource2 = new SqlDataSource();
DataSource2.ID = "SqlDataSource2";
this.Page.Controls.Add(DataSource2);
DataSource2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SEP_Project_NewConnectionString2"].ConnectionString;
DataSource2.SelectCommand = "SELECT courseNo,title from Course";
gridview_modules.DataSource = DataSource2;
gridview_modules.DataBind();
}
The error is as follows
The connection string is ok. How to fix this error?
Upvotes: 2
Views: 2186
Reputation: 3452
Changed the column fields of gridview
Earlier it was like this,
<Columns>
<asp:DynamicField HeaderText="Course No" />
<asp:DynamicField HeaderText="Title" />
</Columns>
then I changed like this,
<Columns>
<asp:BoundField DataField="courseNo" HeaderText="Course No" />
<asp:BoundField DataField="title" HeaderText="Title" />
</Columns>
Upvotes: 0
Reputation: 17590
You have to select something from your SqlDataSource
gridview_modules.DataSource = DataSource2.Select(DataSourceSelectArguments.Empty);
gridview_modules.DataBind();
Upvotes: 1