我有三个复选框:待处理,已批准和已拒绝。我正在使用复选框来过滤我的gridview。
以下是我的过滤代码:
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();
我的问题是,我的已批准和已拒绝的过滤器无效。示例:我检查时
(在前两个场景中工作正常): (1)待处理:gridview将显示处于暂挂状态的帐户,如果没有待处理状态,则不会显示帐户。 (2)待定和已批准:当我检查已批准和待定时,它将显示具有已批准和待定状态的帐户。
(问题) (3)批准或拒绝:假设它将显示具有“已批准”或“已拒绝”状态的帐户,但会发生的情况是,它显示所有帐户
请帮助......
答案 0 :(得分: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();