将 DropDownList 与 DataRow 数组绑定

发布于 2024-11-17 22:43:48 字数 407 浏览 3 评论 0原文

我将 DropDownListDataRow 绑定,但它抛出异常:

数据绑定:“System.Data.DataRow”不包含名为“CourseEligiblility”的属性。

代码:

DataRow[] dRow = dt.Select("CourseID=" + ddlCourse.SelectedValue);
ddlBeStream.DataTextField = "CourseEligiblility";
ddlBeStream.DataValueField = "ID";
ddlBeStream.DataSource = dRow;
ddlBeStream.DataBind();

I am binding the DropDownList with DataRow but it is throwing an exception:

DataBinding: 'System.Data.DataRow' does not contain a property with the name 'CourseEligiblility'.

Code:

DataRow[] dRow = dt.Select("CourseID=" + ddlCourse.SelectedValue);
ddlBeStream.DataTextField = "CourseEligiblility";
ddlBeStream.DataValueField = "ID";
ddlBeStream.DataSource = dRow;
ddlBeStream.DataBind();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冬天旳寂寞 2024-11-24 22:43:48

只需使用将 DataRow Array 复制到新 DataTable 并返回它的函数即可。

//  .
//  .
//  .
ddlBeStream.DataSource = dRow.CopyToDataTable;
ddlBeStream.DataBind();

Just use the function that copies DataRow Array to a new DataTable and returns it.

//  .
//  .
//  .
ddlBeStream.DataSource = dRow.CopyToDataTable;
ddlBeStream.DataBind();
挖鼻大婶 2024-11-24 22:43:48

以 DataView 并按字段过滤

为例。

DataView dv = dt.DefaultView;
dv.RowFilter = "colums=1";
DropDownList1.DataSource = dv;
DropDownList1.DataTextField = "colName";
DropDownList1.DataValueField = "colID";
DropDownList1.DataBind();

Take DataView and filter it by field

for example.

DataView dv = dt.DefaultView;
dv.RowFilter = "colums=1";
DropDownList1.DataSource = dv;
DropDownList1.DataTextField = "colName";
DropDownList1.DataValueField = "colID";
DropDownList1.DataBind();
眼眸 2024-11-24 22:43:48

尝试使用 ddlBeStream.DataBind();

Try using ddlBeStream.DataBind();

土豪我们做朋友吧 2024-11-24 22:43:48

我认为您写错了字段名称。请尝试以下操作:

ddlBeStream.DataTextField = "CourseEligibility";

I think you have made a mistake writing the name of the field. Try the following:

ddlBeStream.DataTextField = "CourseEligibility";
人间☆小暴躁 2024-11-24 22:43:48

对于仍在使用旧版本 ASP.net 的用户:

DataRow[] dRow = dt.Select("CourseID=" + ddlCourse.SelectedValue);
//Copy Datatable and import found rows
System.Data.DataTable dt_Temp = dt.Clone();    
foreach (System.Data.DataRow dr in drRow) { dt_Temp.ImportRow(dr); }

ddlBeStream.DataTextField = "CourseEligiblility";
ddlBeStream.DataValueField = "ID";
//Use new DataTable
ddlBeStream.DataSource = dt_Temp;
ddlBeStream.DataBind();

For people still using older versions of ASP.net:

DataRow[] dRow = dt.Select("CourseID=" + ddlCourse.SelectedValue);
//Copy Datatable and import found rows
System.Data.DataTable dt_Temp = dt.Clone();    
foreach (System.Data.DataRow dr in drRow) { dt_Temp.ImportRow(dr); }

ddlBeStream.DataTextField = "CourseEligiblility";
ddlBeStream.DataValueField = "ID";
//Use new DataTable
ddlBeStream.DataSource = dt_Temp;
ddlBeStream.DataBind();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文