Change If Else with Switch Statement in ASP.Net

akhter
 
on Nov 09, 2021 01:15 AM
588 Views

I am retrieving Data into Textbox, dropdownlist and Label

string strQuery = "select Codeitem,Orderno,Prdqty,PID From Probale where" +
                             " Prdno = @Prdno and DelID is null ";     
SqlCommand cmde = new SqlCommand();
cmde.Parameters.AddWithValue("@Prdno", TextBox1.Text);
cmde.CommandType = CommandType.Text;
cmde.CommandText = strQuery;
cmde.Connection = con;
try
{
    con.Open();
    SqlDataReader sdr = cmde.ExecuteReader();
    while (sdr.Read())
    {
        //DropDownList1.SelectedValue = sdr[0].ToString();
        DropDownList1.SelectedValue = sdr["Codeitem"].ToString();
 
        txtorderno.Text = sdr["Orderno"].ToString();
        txtqty.Text = sdr["Prdqty"].ToString();
        txtpid.Text = sdr["PID"].ToString();
    
        lbmsg.Text = "";
        lbgv.Text = "";
    }
}
catch (Exception ex)
{
    //throw ex;
}
con.Close();

Then i am using IF/Else condition(is it effecive.?)

Now i want to use Switch Statement instead of IF/Else 

below is condition.

if (txtpid.Text != "" && txtpid.Text != "1")
{
    Response.Write("<script language='javascript'>alert('Bale Already Packed');</script>");
 
}
else if(txtOrder.Text == "")
{
    Response.Write("<script language='javascript'>alert('Please Input Orderno');</script>");
    Label1.Text = "";
    TextBox1.Text = "";
    txtqty.Text = "";
    txtorderno.Text = "";
    DropDownList1.SelectedValue = "";
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Nov 09, 2021 09:36 AM

You can't. Switch case is only for individual values. If you want to specify conditions, you need an if else condition.