我正在尝试将gridview绑定到下拉列表,这意味着当我更改我的下拉列表值时,必须相应地在asp.net中显示数据。但是每当我在错误发生后构建应用程序时都会发生:
DataBinding:'System.Data.DataRowView'不包含名为'ClassName'的属性。
我该如何解决这个错误?我已经配置了两个相同数据库的不同表作为gridview和dropdownlist的源。当我在gridview中测试查询时,如果是数据配置,数据以行和列的形式出现,但是当我构建应用程序时,会出现上述错误。我的aspx代码如下:
<asp:GridView ID="Resultgridview" runat="server" AutoGenerateColumns="False"
DataKeyNames="StudentID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="StudentID" HeaderText="StudentID"
InsertVisible="False" ReadOnly="True" SortExpression="StudentID" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Section" HeaderText="Section"
SortExpression="Section" />
<asp:BoundField DataField="StudentName" HeaderText="StudentName"
SortExpression="StudentName" />
<asp:BoundField DataField="RollNo" HeaderText="RollNo"
SortExpression="RollNo" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="GuardianName" HeaderText="GuardianName"
SortExpression="GuardianName" />
<asp:BoundField DataField="GuardianPhone" HeaderText="GuardianPhone"
SortExpression="GuardianPhone" />
</Columns>
</asp:GridView>
我的cs代码看起来像这样
protected void ClassDropdownlist_SelectedIndexChanged(object sender, EventArgs e)
{
Resultgridview.DataSource = SqlDataSource1;
Resultgridview.DataBind();
//SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=dbbilling;User ID=sa;Password=sa123");
//SqlDataAdapter da = new SqlDataAdapter("select StudentName from students where Class='" + ClassDropdownlist.SelectedItem.Text + "'", con);
//DataTable dt = new DataTable();
}
我必须在cs文件中添加和取消注释?