ASP.NET - how to change if condition in ternary operator in c#.net

Asked By ramar yadav on 25-Jan-13 01:30 AM

hi

how to change if condition in ternary operator in c#.net

example for

// bind to datagridview //

private void binddatagrid(string argstr)
        {
            string str = "";
            if (argstr != "")
                argstr = " WHERE " + argstr;
            str = @"select RL.requeslist,RL.date, U.first_name, S.status_name from tb1_requestlist RL inner join tbl_user U ON RL.assign= U.id_user inner join tbl_status S ON RL.status=S.id_status" + argstr;
            adp = new SqlDataAdapter(str, conn);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            dataGridView1.DataSource = dt;
        }

// bind to combox//

private void bindddl()
  {
            adp = new SqlDataAdapter(@"select '0' as id_status,'-- Select --' as status_name UNION select id_status, status_name from tbl_status", conn);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            cmbstatus.DisplayMember = "status_name";
            cmbstatus.ValueMember = "id_status";
            cmbstatus.DataSource = dt;
}
private void btnsearch_Click(object sender, EventArgs e)
{
string status_id = cmbstatus.SelectedValue.ToString();
 if (status_id != "0")
            {
                if (value != "")
                    value += " AND ";
                value += " S.id_status= '" + status_id + "' ";
            }

binddatagrid(value);
}












Danasegarane Arunachalam replied to ramar yadav on 25-Jan-13 06:50 AM
Where you want to change?

Bold those Lines
Murugan V replied to ramar yadav on 11-Feb-13 10:12 PM
value += (value != ""  ?  " AND " : " S.id_status= '" + status_id + "' ");  
ramar yadav replied to Murugan V on 12-Feb-13 01:15 AM
thank u Murugan. V

Already i have code for this one

value += value == string.Empty ? "" : " AND ";
                value += "S.id_status= '" + status_id + "' ";


and ur code is very short.. thank u