0

我正在绑定一个 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();
    }
}

我收到一个错误,例如Filter expression 'FirstName ' does not evaluate to a Boolean termDataRow[] rows = ds.Tables[0].Select(expression);

谁能帮我这个??

4

2 回答 2

1

你的表达没有任何意义。我会期待一些类似的东西:

var expression = "FirstName = 'John'";

或者

var expression = "CategoryId = 42";

查看 Select 方法的文档:http: //msdn.microsoft.com/en-us/library/det4aw50.aspx

于 2012-10-24T12:28:47.063 回答
0

您需要比较表达式中的 2 个值。阅读本文:C# 数据表选择

于 2012-10-24T12:30:06.007 回答