我收到此c#代码的错误
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();
}
错误如下
连接字符串正常。如何解决此错误?
答案 0 :(得分:1)
您必须从SqlDataSource
gridview_modules.DataSource = DataSource2.Select(DataSourceSelectArguments.Empty);
gridview_modules.DataBind();
答案 1 :(得分:0)
更改了gridview的列字段
之前就是这样,
<Columns>
<asp:DynamicField HeaderText="Course No" />
<asp:DynamicField HeaderText="Title" />
</Columns>
然后我改变了这个,
<Columns>
<asp:BoundField DataField="courseNo" HeaderText="Course No" />
<asp:BoundField DataField="title" HeaderText="Title" />
</Columns>