0

我有三个复选框:待处理、已批准和已拒绝。我正在使用复选框来过滤我的网格视图。

这是我的过滤代码:

    string sqlfilter = "id >= 1";
    DataView dv = new DataView(ClassBiller.FilterPendingConsumer());

    if (Pend.Checked)
    {
        sqlfilter += " AND (Status = 'Pending')";
    }

    if (Approve.Checked)
    {
        sqlfilter += " OR (Status = 'Approved')";
    }

    if (Reject.Checked)
    {
        sqlfilter += " OR (Status = 'Rejected')";
    }

    dv.RowFilter = sqlfilter;

    gvtransaction.DataSource = dv;
    gvtransaction.DataBind();

我的问题是,我的 Approved 和 Rejected 过滤器不起作用。示例:当我检查时

(在前两个场景中运行良好):(1)待处理:gridview 将显示处于待处理状态的帐户,如果没有待处理状态,它将不显示任何帐户。(2) Pending and Aprroved : 当我检查approved和Pending时,它会显示处于Approved和Pending状态的账户。

(问题) (3) Approved or Rejected :假设它会显示具有 Approved 或 Rejected 状态的帐户,但结果是,它显示了所有帐户

请帮忙...

4

1 回答 1

1

尝试这个

string sqlfilter = "id >= 1";
        DataView dv = new DataView(ClassBiller.FilterPendingConsumer());

        if (Pend.Checked)
        {
            sqlfilter += " AND (Status = 'Pending')";
        }

        if (Approve.Checked)
        {
            sqlfilter += (sqlfilter.Contains("AND") ? "OR" : "AND") + " (Status = 'Approved')";
        }

        if (Reject.Checked)
        {
            sqlfilter += (sqlfilter.Contains("AND") ? "OR" : "AND") + " (Status = 'Rejected')";
        }

        dv.RowFilter = sqlfilter;

        gvtransaction.DataSource = dv;
        gvtransaction.DataBind();
于 2013-06-05T07:19:12.490 回答