| Author: Roopesh Babu Valluru 03 Dec 2008 | Member Level: Gold | Rating:  Points: 6 |
Hi...
First add all the conditions that has AND and then OR and ur req becomes like :
c='some' and (code like 'a%' or name like 'b%')
now...
if (txtCode.Text.Trim() != "") { //this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition); this.SearchCondition += "Code LIKE '" + txtCode.Text.Trim() +"%' and "; }
if (txtName.Text.Trim() != "" || ddlJob.SelectedIndex > 0) { this.SearchCondition += "("; }
if (txtName.Text.Trim() != "") { this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition); this.SearchCondition += "Name LIKE '" + txtName.Text.Trim() + "%' or "; } if (ddlJob.SelectedIndex > 0) { this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition+" or"); this.SearchCondition += "Job = '" + ddlJob.SelectedItem.Text + "'"; } if (txtName.Text.Trim() != "" || ddlJob.SelectedIndex > 0) { this.SearchCondition += ")"; }
Hope the above will work..
All Teh Best...
|
| Author: Preet 03 Dec 2008 | Member Level: Gold | Rating:  Points: 6 |
hi,
i have code like this below
if (txtCode.Text.Trim() != "") { //this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition); this.SearchCondition += "(Code LIKE '" + txtCode.Text.Trim() +"%'"; } if (txtName.Text.Trim() != "") { this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " OR " : this.SearchCondition); this.SearchCondition += "Name LIKE '" + txtName.Text.Trim() + "%')"; } else this.SearchCondition += ")" if (ddlJob.SelectedIndex > 0) { this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition); this.SearchCondition += "Job = '" + ddlJob.SelectedItem.Text + "'"; } if (ddlStatus.SelectedIndex > 0) { this.SearchCondition = (this.SearchCondition != string.Empty ? this.SearchCondition + " AND " : this.SearchCondition); this.SearchCondition += "Status = '" + ddlStatus.SelectedItem.Text + "'"; }
|