Thursday, July 26, 2018

how to perform NESTED IF ELSE in asp.net | sradha webcreations

how to perform NESTED IF ELSE in asp.net 


NESTED IF ELSE
ENTER A NUMBER
OUTPUT

SAVE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;

public partial class NESTEDIF : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ButtonSAVE_Click(object sender, EventArgs e)
    {
        string connectionstring=ConfigurationManager.ConnectionStrings ["dbconnection"].ConnectionString;
        string insertsql = "insert into nestedif(enternumber,output)values(@enternumber,@output)";

        using (SqlConnection myconnection = new SqlConnection(connectionstring))
        {
            myconnection.Open();
            SqlCommand mycommand = new SqlCommand(insertsql,myconnection);
            mycommand.Parameters.AddWithValue("@enteranumber",TextBoxNUMBER.Text);
            mycommand.Parameters.AddWithValue("@output",TextBox2.Text);

            mycommand.ExecuteNonQuery();
            myconnection.Close();
        }

        TextBoxNUMBER.Text=string.Empty;
        TextBox2.Text=string.Empty;

        }

  protected void TextBoxNUMBER_TextChanged(object sender, EventArgs e)
    {
        int iDay = Convert.ToInt32(TextBoxNUMBER.Text);

        if (iDay == 1)
        {
            TextBox2.Text = "SUNDAY";
        }
        else if (iDay == 2)
        {
           TextBox2.Text = "MONDAY";
        }
        else if (iDay == 3)
        {
            TextBox2.Text = "TUESDAY";
        }
        else if (iDay == 4)
        {
            TextBox2.Text = "WEDNESDAY";
        }
        else if (iDay == 5)
        {
            TextBox2.Text = "THURSDAY";
        }
        else if (iDay == 6)
        {
            TextBox2.Text = "FRIDAY";
        }
        else if (iDay == 7)
        {
            TextBox2.Text = "SATURDAY";
        }
        else
        {
            TextBox2.Text = "invalid entry";
        }
    }

}





No comments:

Post a Comment