我正在绑定一个DropDownList,我在第一列中有FirstName而在第二列中有LastName作为DDL
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
DataTable myTable = new DataTable();
DataColumn productIDColumn = new DataColumn("FirstName");
DataColumn productNameColumn = new DataColumn("LastName");
myTable.Columns.Add(productNameColumn);
DataSet ds = new DataSet();
ds = get();
if (e.Row.RowType == DataControlRowType.DataRow)
{
var categoryID = (e.Row.Cells[0].Text);
var expression = "FirstName "+categoryID;
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
DataRow[] rows = ds.Tables[0].Select(expression);
foreach (DataRow row in rows)
{
DataRow newRow = myTable.NewRow();
newRow["UserId"] = row["UserId"];
newRow["LastName"] = row["LastName"];
myTable.Rows.Add(newRow);
}
ddl.DataSource = myTable;
ddl.DataTextField = "LastName";
ddl.DataValueField = "UserId";
ddl.DataBind();
}
}
我在DataRow [] rows = ds.Tables [0]收到类似Filter expression 'FirstName ' does not evaluate to a Boolean term
的错误.Select(expression);
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:1)
你的表达没有任何意义。我期待的是:
var expression = "FirstName = 'John'";
或
var expression = "CategoryId = 42";
查看Select方法的文档:http://msdn.microsoft.com/en-us/library/det4aw50.aspx
答案 1 :(得分:0)
您需要比较表达式中的2个值。阅读这篇文章:C# DataTable Select