0
votes

I am binding a DropDownList, I have FirstName in the 1st column and LastName as a DDL in the second column

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();
    }
}

I am getting an error like Filter expression 'FirstName ' does not evaluate to a Boolean term at DataRow[] rows = ds.Tables[0].Select(expression);

Can anyone help me with this??

2
Does 'DDL' mean a Drop Down List in this context? - RQDQ

2 Answers

1
votes

Your expression doesn't make any sense. I would expect something along the lines of:

var expression = "FirstName = 'John'";

or

var expression = "CategoryId = 42";

Check out the docs for the Select method: http://msdn.microsoft.com/en-us/library/det4aw50.aspx

0
votes

You need to compare 2 values in your expression. Read this article: C# DataTable Select