2

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 enter image description here

The connection string is ok. How to fix this error?

4

2 に答える 2

1

から何かを選択する必要があります。SqlDataSource

gridview_modules.DataSource = DataSource2.Select(DataSourceSelectArguments.Empty);
gridview_modules.DataBind();
于 2013-07-11T08:08:49.767 に答える
0

グリッドビューの列フィールドを変更しました

以前はこんな感じでしたが、

<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>
于 2013-07-11T08:17:52.863 に答える