mercredi 6 janvier 2021

How to do javascript for this if-else statement and connect them into database?

namespace WebApplication27
{
public partial class TestingDB : System.Web.UI.Page
{
    string A;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Btn1_Click(object sender, EventArgs e)
    {
        if (DD1.SelectedIndex == 1)
        {
            A = "A";
        }
        else if (DD1.SelectedIndex == 2)
        {
            A = "B";
        }
        else if (DD1.SelectedIndex == 3)
        {
            A = "C";
        }
        else
        {
            A = "D";
        }



        String query = "Insert INTO Test (SelectValue,DsiplayValue)values('" + A + "','" + TextB1.Text + "')";
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["HelloWorldConnectionString"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = query;
        cmd.Connection = con;
        cmd.ExecuteNonQuery();
    }
}

}

Im doing a interface where it have a dropdown list and a text box. I have already connect dropdownlist and the textbox to pass it's value. Dropdownlist (id=DD1) and a textbox (id=TextB1). This is my code where it connects to database. Can I do javascript instead of doing if else statement ?

Aucun commentaire:

Enregistrer un commentaire