DropDownList控件为什么绑定不上数据源。
代码如下:
BLL_SortPolitics sort = new BLL_SortPolitics();
DataTable dt_sort = new DataTable();
dt_sort = sort.sortpolitics_select_all();
DropDownList_Sort.DataSource = dt_politics;
DropDownList_Sort.DataTextField = "Name";
DropDownList_Sort.DataValueField = "ID";问题:在这里出现提示信息“DataBinding:“System.Data.DataRowView”不包含名为“Name”的属性。”。但在数据库中是存在这个“Name”属性的。因为“dt_sort.Rows[0][“Name”]”和“dt_sort.Rows[0][“ID”]”都有值,说明“Name”属性不为空啊!这是什么原因???
DropDownList_Sort.DataBind();DropDownList控件前台代码:
类别:<asp:DropDownList ID="DropDownList_Sort" runat="server" CssClass="admin_control">
</asp:DropDownList>
代码如下:
BLL_SortPolitics sort = new BLL_SortPolitics();
DataTable dt_sort = new DataTable();
dt_sort = sort.sortpolitics_select_all();
DropDownList_Sort.DataSource = dt_politics;
DropDownList_Sort.DataTextField = "Name";
DropDownList_Sort.DataValueField = "ID";问题:在这里出现提示信息“DataBinding:“System.Data.DataRowView”不包含名为“Name”的属性。”。但在数据库中是存在这个“Name”属性的。因为“dt_sort.Rows[0][“Name”]”和“dt_sort.Rows[0][“ID”]”都有值,说明“Name”属性不为空啊!这是什么原因???
DropDownList_Sort.DataBind();DropDownList控件前台代码:
类别:<asp:DropDownList ID="DropDownList_Sort" runat="server" CssClass="admin_control">
</asp:DropDownList>
改为
DropDownList_Sort.DataSource=dt_sort;因为你选错数据源了
数据源错误DropDownList_Sort.DataSource=dt_sort;
改为
DropDownList_Sort.DataSource = dt_sort;
改为
DropDownList_Sort.DataSource=dt_sort;因为你选错数据源了LZ 以后要仔细哦,别遇到问题就问,多调试 ,所有问题都在胯下,拿下它们不再是问题。
希望对你有帮助