Tuesday 22 April 2014

Transfer the content from DropdownList1 to DropdownList2 and vice versa.



Create a web application with two DropdownList1 & DropdownList2 and design application to transfer the  content from  DropdownList1 to DropdownList2  and vice versa.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ADO.net_Tutorial
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ListItem selecteditem = new ListItem("Select", "7");

                ListItem item1 = new ListItem("One", "1");
                ListItem item2 = new ListItem("Two", "2");
                ListItem item3 = new ListItem("Three", "3");

                ListItem item4 = new ListItem("Four", "4");
                ListItem item5 = new ListItem("Five", "5");
                ListItem item6 = new ListItem("Six", "6");

                selecteditem.Selected = true;
               DropDownList1.Items.Add(selecteditem);
               DropDownList2.Items.Add(selecteditem);

               DropDownList1.Items.Add(item1);
               DropDownList1.Items.Add(item2);
                DropDownList1.Items.Add(item3);

             DropDownList2.Items.Add(item4);
             DropDownList2.Items.Add(item5);
             DropDownList2.Items.Add(item6);

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            ListItem[] List1Array = new ListItem[DropDownList1.Items.Count];
           DropDownList1.Items.CopyTo(List1Array, 0);

            ListItem[] List2Array = new ListItem[DropDownList2.Items.Count];
           DropDownList2.Items.CopyTo(List2Array, 0);

           DropDownList1.Items.Clear();
            DropDownList2.Items.Clear();
          
            foreach (ListItem myItem in List1Array)
            {                
                DropDownList2.Items.Add(myItem.Text);
            }

            foreach (ListItem myItem in List2Array)
            {
           DropDownList1.Items.Add(myItem.Text);
            }
        }
    }
}

Output:-



If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Thank you so much :)

Sunday 20 April 2014

Single Dimensional Array

Accept and print the single dimensional array.

using System;

namespace TestArray
{
class program
{
   static void Main(string[] args)
       {
           int[] arr1 = new int[5];
           Console.WriteLine("Enter the value for array:");
           for(int i=0; i<5; i++)
           {
           arr1[i]= Convert.ToInt16(Console.ReadLine());
           }
           Console.WriteLine("Display the single dimensional array:");
           foreach (int i in arr1)
           {
               Console.WriteLine(i);
           }
           Console.ReadKey();
       }       
}
}

Multidimensional Array

Accept the value for multidimensional  array from user and print the it  in matrix format.

using System;
namespace testArray
{
    class Program
    {
        static void Main(string[] args)
        {Console.WriteLine("Enter the value for multidimensional array:");
            int[,] arr1 = new int[3, 2];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    arr1[i, j] = Convert.ToInt32(Console.ReadLine());
                }
            }
                      Console.WriteLine("Displaying the multidimensional array in matrix format :");

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.Write(arr1[i, j] +"  ");
                }
                Console.WriteLine( "\n");
               }
            Console.ReadKey();
        }
    }
}

Output:-
Enter the value for multidimensional array:
2
3
5
9
1
0

Displaying the multidimensional array in matrix format :
2  3
5  9
1  0


Jagged array.


Accept and print the value of jagged array.

using System;

namespace JaggedArray
{
    class Program
    {
        static void Main(string[] args)
        {         
            int[][] jagged = new int[3][];

            Console.WriteLine("Enter value for 1st row:");
            jagged[0] = new int[3];
            for (int i = 0; i < 1; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    jagged[i][j] = Convert.ToInt32(Console.ReadLine());
                }
            }

            Console.WriteLine("Enter value for 2nd row:");
            jagged[1] = new int[2];
            for (int i = 1; i < 2; i++)
            {
                for (int j = 0; j <2; j++)
                {
                    jagged[i][j] = Convert.ToInt32(Console.ReadLine());
                }
            }

            Console.WriteLine("Enter value for 3rd row;");
            jagged[2] = new int[4];
            for (int i = 2; i < 3; i++)
            {
                for (int j = 0; j<4; j++)
                {
                    jagged[i][j] = Convert.ToInt32(Console.ReadLine());
                }
            }

            // Print out all elements in the jagged array.
            Console.WriteLine("\n Jagged array:");
            for (int i = 0; i <3; i++)
            {
                int[] newArray = jagged[i];
                for (int j = 0; j < newArray.Length; j++)
                {
                    Console.Write(newArray[j] + " ");   
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}

Output:- 

Enter value for 1st row:
0
9
3
Enter value for 2nd row:
8
4
Enter value for 3rd row:
1
5
3
6

Jagged array:
0  9  3
8  4
1  5  3  6

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Thank you so much :)


Bind (display) data in gridview using ADO.net disconneted achitechture

WAP to display data in ASP.Net GridView Control from SQL  Database using ADO.Net disconnected Architecture.

Explanation:- Please check the explanation of ADO.Net connected Architecture program.

WebForm1.aspx.cs



using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace ADO.net_Tutorial
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //bind gridviw using disconnted architechture of ado.net
            string constr = ConfigurationManager.ConnectionStrings["testconstr"].ConnectionString;
            SqlConnection con = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand(" select * from EmployeeDetails", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
    }
}

Bind (display) data in gridview using ADO.net conneted achitechture



WAP to display data in ASP.Net GridView Control from SQL  Database using ADO.Net connected Architecture.

Explanation:- for this program, first  you have create a sql server database table ( "EmployeeDetails" ) with few Data fields like EmpID, EmName etc ,And then  create a connection string in web.config file with "testconstr" name, using  following code.
but make sure the Data Source path and AttachDbFilename  path is right or not because in following code I am using my database path.

<connectionStrings>
     <add name="testconstr" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=C:\Users\MAKANSINGH\Documents\test.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

And then open a web page and drop a GridView control  on the webpage from ToolBox ->Data-> Gridview. then write the following code in code behind file and run your program.

If you have any doubt please contact me.

WebForm1.aspx.cs


using System;
using System.Data.SqlClient;
using System.Configuration;

namespace ADO.net_Tutorial
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            string constr = ConfigurationManager.ConnectionStrings["testconstr"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                SqlCommand cmd = new SqlCommand(" select * from EmployeeDetails", con);
                con.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
            }
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Thank you so much :)

Transfer data from one web page to another using cookie collection

Accept ItemId, Name and Quantity and store them in cookie collection and show them in next form.

Explanation:- First create two web page in asp.net with name of  Webform1 or WebForm2 ,  where you have to drop some asp.net control to accept  and display the input./output as per as the program requirement  (like TextBox, Label, Button etc) and then finally write down the the  code in the code behind  file respectively. 


WebForm1.aspx.cs

using System;
using System.Web;
using System.Web.UI;

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

        }        
        protected void Button1_Click(object sender, EventArgs e)
        {
            int itemid = Convert.ToInt32(TextBox1.Text);
            string itemname = TextBox2.Text;
            int qty = Convert.ToInt32(TextBox3.Text);

            HttpCookie cookies = new HttpCookie("productdetails");
            cookies["itemid"] = Convert.ToString(itemid);
            cookies["itemname"] = itemname;
            cookies["qty"] =Convert.ToString(qty);

            cookies.Expires = DateTime.Now.AddHours(1);
            Response.Cookies.Add(cookies);

           Response.Redirect("WebForm2.aspx");
           }
    }
}

WebForm2.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Architecture
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookies = Request.Cookies["productdetails"];
            if (cookies != null)
            {
                Label1.Text = cookies["itemid"];
                Label2.Text = cookies["itemname"];
                Label3.Text = cookies["qty"];
            }
        }
    }
}
If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Thank you so much :)

Using while loop calculate A power B.

WAP to accept two  number  from user & Using while loop calculate A power B.


using System;
using System.Text;

namespace PowerOfNumber
{
    class Program
    {
        static void Main(string[] args)
        {        
        int num1, num2;
        int power = 1;
        int i = 1;
        Console.WriteLine("Enter a number:");
        num1 = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter a power number:");
        num2 = Convert.ToInt32(Console.ReadLine());
        while (i<= num2)
        {
            power = power * num1;
            i = i + 1;
        }
          
        Console.WriteLine(num1 + " 's  Power  " +num2 + " is :  " +power + " .!");
        Console.ReadKey();
       }
    }
}

If Else statement

Demonstration of if else statement in C#.

using System;
using System.Text;

namespace ifstatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a Character:");
            char c = (char)Console.Read();

            if (Char.IsUpper(c))
            {
                Console.WriteLine("Character is UpperCase..!");
            }
            else if (Char.IsLower(c))
            {
                Console.WriteLine("Character is LowerCase..!");
            }
            else if (Char.IsDigit(c))
            {
                Console.WriteLine("Character is a number..!");
            }
            else
            {
            Console.WriteLine("Character is not a alphanumeric.!");
            }
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Thank you so much :)
       

Write a program in c# (c sharp) to  Check whether given number is Palindrome number or not .

using System;

namespace PalindromeNumber
{
    class Program
    {
        static void Main(string[] args)
        {   int num, rem, sum = 0, temp;
            Console.WriteLine("Enter a number: ");
            num = Convert.ToInt32(Console.ReadLine());
            temp = num;
            while (Convert.ToBoolean(num))
            {
                rem = num % 10;
                num = num / 10;
                sum = sum * 10 + rem;
            }
            Console.WriteLine("\n The Reversed Number is: {0} \n", sum);
            if (temp == sum)
            {
                Console.WriteLine("Number is Palindrome \n");
            }
            else
            {
                Console.WriteLine("Number is not a palindrome..!");
            }
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Thank you so much :)

Reverse of a string


Write a program in c# (c sharp) to   accept a string from user and display the  reverse of a string .

using System;

namespace ReverseofString
{

   class Program
    {
    static void Main(string[] args)
    {
            string str1, str2 = "";
            int len, i;
            Console.WriteLine("Enter a String:");
            str1 = Console.ReadLine();
            len = str1.Length;
            for (i = len - 1; i >= 0; i--)
            {
                str2 = str2 + str1[i];
            }
            Console.WriteLine("Reverse of the entered string is:  " + str2);
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Check wheather given number is Armstrong or not


Write a program in c# (c sharp) to  Check whether given number is Armstrong or not .

using System;

namespace ArmStrongNumber
{

    class Program
    {
        static void Main(string[] args)
        {           
             int num, temp, sum, d1;
            Console.WriteLine("Enter a number");
            num = Convert.ToInt32(Console.ReadLine());
            sum = 0;
            temp = num;
            while (Convert.ToBoolean(num))
            {
                d1 = num % 10;
                num = num / 10;
                sum = sum + (d1 * d1 * d1);
            }

            if (sum == temp)
            {
                Console.WriteLine(" Entered numeber is an armstrong number..!");
            }
            else
            {
                Console.WriteLine(" Entered number is not an armstrong number..!");
            }
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".


Prime number between 1 to 50

Write a program in c# (c sharp) to  find out the Prime Numbers between series of  1 -50 numbers.


using System;

namespace PrimeNumber
{
class Program
{
    static void Main(string[] args)
    {
        bool prime = true;
        Console.WriteLine("Prime Numbers Bet: ");
        for (int i = 2; i <= 50; i++)
        {
            for (int j = 2; j <= 50; j++)
            {

                if (i != j && i % j == 0)
                {
                    prime = false;
                    break;
                }
            }
            if (prime)
            {
                Console.WriteLine(i);
            }
            prime = true;
        }
        Console.ReadKey();
    }
}
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".

Armstrong number between 100 to 500


Write a program in c# (c sharp) to  find out the Armstrong Numbers between series of  100 -500 numbers.


using System;

namespace ArmStorngNumber
{
class Program
{
    static void Main(string[] args)
    {
            int num, sum, d, i, j;
            Console.WriteLine("Armstrong Numbers between 100 to 500:");
            for (i = 100; i <= 500; i++)
            {
                j = 1;
                sum = 0;
                num = i;
                while (j <= 3)
                {
                    d = num % 10;
                    sum = sum + (d * d * d);
                    num = num / 10;
                    j++;
                }
                if (sum == i)
                {
                    Console.WriteLine(i);
                }
            }
            Console.ReadKey();
        }
    }
}


If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com"

Thank you so much  :)

Ascending and descending order of array


Write a program in c# (c sharp) to accept 10 numbers in to array  form user and display it in Ascending and descending order.


using System;

namespace SortingOfArray
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] numarr = new int[10];

            Console.WriteLine("Enter  numbers :");
            for (int i = 0; i < 10; i++)
            {
                numarr[i] = Convert.ToInt32(Console.ReadLine());
            }

            Console.WriteLine("Ascending order of numbers :");
            Array.Sort(numarr);
            for(int i=0; i<10; i++)
            {
                Console.WriteLine(numarr[i]);
            }

            Console.WriteLine("Descending order of numbers :");
            Array.Sort(numarr);
            Array.Reverse(numarr);
            for(int i =0; i<10; i++)
            {
                Console.WriteLine(numarr[i]);
            }
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com"

Thank you so much  :)