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 'CourseEligiblili开发者_如何学Pythonty'.
Code:
DataRow[] dRow = dt.Select("CourseID=" + ddlCourse.SelectedValue);
ddlBeStream.DataTextField = "CourseEligiblility";
ddlBeStream.DataValueField = "ID";
ddlBeStream.DataSource = dRow;
ddlBeStream.DataBind();
Just use the function that copies DataRow Array to a new DataTable and returns it.
// .
// .
// .
ddlBeStream.DataSource = dRow.CopyToDataTable;
ddlBeStream.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();
Try using ddlBeStream.DataBind();
I think you have made a mistake writing the name of the field. Try the following:
ddlBeStream.DataTextField = "CourseEligibility";
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();
精彩评论