You are on page 1of 54

Program 1: Write a C# program to print name using Alias name.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using A = System.Console; namespace Program1 { class Program { static void Main(string[] args) { A.WriteLine("Enter name"); string s = A.ReadLine(); A.WriteLine("Name:=" + s); } } }

Program 2: Write a C# program to implement Value Parameters.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program2 { class Program { static void show(int p1, int p2) { Console.WriteLine("sum=" + (p1 + p2)); } static void Main(string[] args) { show(10, 20); } } }

Program 3: Write a C# program to implement Reference Parameters.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program3 { class Program { static void show(ref int p1, ref int p2) { p1 = p1 + 100; p2 = p2 + 100; } static void Main(string[] args) { int x=10,y=20; Console.WriteLine("Before X="+x+"and Y="+y); show(ref x, ref y); Console.WriteLine("After X="+x+"and Y="+y); } } }

Program 4: Write a C# program to implement Parameter Arrays.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program4 { class Program { static void show(params int[] p1) { Console.WriteLine("output=\n"); foreach (int i in p1) { Console.WriteLine("value=" + i); } Console.WriteLine("*********"); } static void Main(string[] args) { show(10); show(10, 20); show(); show(1, 2, 3, 4, 5, 6); } } }

Program 5: Write a C# program to implement Output Parameters.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program5 { class Program { static void show(int p1, out int p2) { p2 = p1 * p1; } static void Main(string[] args) { int y; show(10, out y); Console.WriteLine("Y=" + y); } } }

Program 6: Write a C# program to print reverse of an array.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program6 { class Program { static void Main(string[] args) { int[] arr = new int[5] { 1, 2, 3, 4, 5 }; Array.Reverse(arr); foreach (int i in arr) { Console.WriteLine("Answer=" + i); } } } }

Program 7: Write a C# program to print the elements from one array to another array.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program7 { class Program { static void Main(string[] args) { int[] arr1 = new int[5] { 1, 2, 3, 4, 5 }; int[] arr2 = new int[10]{11,12,13,14,15,16,17,18,19,20}; arr1.CopyTo(arr2, 0); foreach (int i in arr2) { Console.WriteLine("Answer=" + i); } } } }

Program 8: Write a C# program to sort a given array.

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace Program8 { class Program { static void Main(string[] args) { int[] arr = new int[7] { 7,5,4,3,6,1,2}; Array.Sort(arr); foreach (int i in arr) { Console.Write(i); Console.Write(' '); } Console.WriteLine(); } } }

Program 9: Write a C# program to add items to the Arraylist.

using System.Text; using System.Collections; namespace Program9 { class Program { static void Main(string[] args) { ArrayList AL1 = new ArrayList(); AL1.Add("One"); AL1.Add("Two"); AL1.Add("Three"); AL1.Add("Four"); // display(AL1); foreach (object i in AL1) { Console.WriteLine(i); Console.WriteLine(' '); } } } }

Program 10: Write a C# program to combine two Arraylists using Addrange method.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Program10 { class Program { static void Main(string[] args) { ArrayList list1 = new ArrayList(); list1.Add(1); list1.Add(2); ArrayList list2 = new ArrayList(); list2.Add(3); list2.Add(4); list1.AddRange(list2); foreach (int i in list1) { Console.WriteLine(i); } } } }

Program 11: Write a C# program to insert and remove values from an Arraylist.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Program11 { class Program { static void Main(string[] args) { ArrayList list = new ArrayList(); list.Add("Java"); list.Add("PHP"); list.Add("Dotnet"); list.Add("C"); list.RemoveAt(1); list.Insert(0, "JSP"); foreach (string str in list) { Console.WriteLine(str); } } } }

Program 12: Write a C# program to sort and reverse an Arraylist. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Program12 { class Program { static void Main(string[] args) { ArrayList list = new ArrayList(); list.Add("Java"); list.Add("PHP"); list.Add("Dotnet"); list.Add("C"); list.Add("JSP"); list.Sort(); foreach (string str in list) { Console.WriteLine(str); } Console.WriteLine(' '); list.Reverse(); foreach (string str in list) { Console.WriteLine(str); } } } }

Program 13: Write a C# program to use the count and capacity properties of Arraylist.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Program13 { class Program { static void Main(string[] args) { ArrayList list = new ArrayList(); list.Add("Java"); list.Add("PHP"); list.Add("Dotnet"); list.Add("C"); Console.WriteLine(list.Count); Console.WriteLine(' '); Console.WriteLine(list.Capacity);

} } }

Program 14: Write a C# program to implement Copy,concat and compare methods of Strings.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program14 { class Program { static void Main(string[] args) { string s1 = "Hello"; string s2 = "World"; string s3 = "Welcome"; string s5 = string.Copy(s1); Console.WriteLine(s5); Console.WriteLine(' '); string s4 = string.Concat(s1,' ', s2,' ', s3); Console.WriteLine(s4); Console.WriteLine(' '); int a = string.Compare(s1, s2); Console.WriteLine(a); } } }

Program 15: Write a C# program to implement various other methods of strings.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program15 { class Program { static void Main(string[] args) { string s1 = "Hello World"; Console.WriteLine(s1.Equals("hello")); Console.WriteLine(' '); Console.WriteLine(s1.Substring(3)); Console.WriteLine(' '); Console.WriteLine(s1.StartsWith("we")); Console.WriteLine(' '); Console.WriteLine(s1.IndexOf("r")); Console.WriteLine(s1.LastIndexOf("d")); Console.WriteLine(' '); string s2= "Welcome Everyone"; Console.WriteLine(s2.Replace('l','o')); Console.WriteLine(' ');

} } }

Program 16: Write a C# program to implement Verbatim String.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program16 { class Program { static void Main(string[] args) { string s1, s2, s3, s4; s1 = "D:\\IT-VII\\dotnet"; Console.WriteLine(s1); s2= @"D:\\IT-VII\\dotnet"; Console.WriteLine(s2); s3= "Hello\nWorld"; Console.WriteLine(s3); s4= @"Hello\nWorld"; Console.WriteLine(s4); } } }

Program 17: Write a C# program to implement Method Overriding.

using System; using System.Collections.Generic; namespace Program17 { class A { int x=10; public void disp() { Console.WriteLine("Value of X="+x); } public void disp(int p1) { x = p1; Console.WriteLine("Now value of x=" + x); } } class Program { static void Main(string[] args) { A ob = new A(); ob.disp(); ob.disp(1111); } } }

Program 18: Write a C# program to implement Contructors.

using System; using System.Collections.Generic; namespace Program18 { class A { int x; public A() //empty constructor { x = 1001; } public A(int p2) //parameterised constructor { x=p2; } public void disp() { Console.WriteLine("value of x=" + x); } } class Program { static void Main(string[] args) { A ob1 = new A(); A ob2 = new A(12345); ob1.disp(); ob2.disp(); } } }

Program 19: Write a C# program to implement Copy Constructor.

using System; using System.Collections.Generic; namespace Program19 { class A { int x, y; public A() {} public void get() { Console.WriteLine("Enter a no"); x = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter a no"); y = Convert.ToInt32(Console.ReadLine()); } public A(A obj) { Console.WriteLine("Copy Constructor"); x = obj.x; y = obj.y; } public void disp() { Console.WriteLine("value of x=" + x+"value of y="+y); } } class Program { static void Main(string[] args)

A obj1 = new A(); obj1.get(); obj1.disp(); A obj2 = new A(obj1); obj2.disp(); } } }

Program 20: Write a C# program to implement Method Overriding using Virtual and Override methods.

using System; using System.Collections.Generic; namespace Program20 { class A { int x; public A() { x = 10; } public virtual void disp() { Console.WriteLine("value of x=" + x); } } class B : A { int y; public B() { y = 20; } public override void disp() { Console.WriteLine("value of y=" + y); } } class Program { static void Main(string[] args) { B obj = new B(); obj.disp(); } } }

Program 21: Write a C# program to implement method overriding using New keyword. using System; using System.Collections.Generic; namespace Program21 { class A { int x = 10; public void show() { Console.WriteLine("value of x=" + x); } } class B : A { int y = 20; public new void show() { Console.WriteLine("value of y=" + y); } } class Program { static void Main(string[] args) { B obj = new B(); obj.show(); } } }

Program 22: Write a C# program to implement Sealed keyword.

using System; using System.Collections.Generic; namespace Program22 { class A { int x = 50; public sealed void show() { Console.WriteLine("value of x=" + x); } } class B : A { int y = 70; public void show() // Error { Console.WriteLine("value of y=" + y); } } class Program { static void Main(string[] args) { B obj = new B(); obj.show(); } } }

Program 23: Write a C# program to implement const keyword.

using System; using System.Collections.Generic; namespace Program23 { class A { public const int x = 100; public void show() { Console.WriteLine("value of x=" + x); } } class Program { static void Main(string[] args) { A obj1 = new A(); //obj1.x = 123; // gives error since X becomes constant obj1.show(); Console.WriteLine("constant value=" + A.x); } } }

Program 24: Write a C# program to implement Readonly keyword.

using System; using System.Collections.Generic; namespace Program24 { class A { public readonly int x; public A() { x = 1000; } public void show() { Console.WriteLine("value of x=" + x); } } class Program { static void Main(string[] args) { A obj = new A(); // obj.x = 1223; //gives error obj.show(); Console.WriteLine("constant value=" + obj.x); } } }

Program 25: Write a C# program to implement Interface.

using System; using System.Collections.Generic; namespace Program25 { interface IA { void show(); } interface IB { void disp(); } class A { } class B : A, IA, IB { void IA.show() { Console.WriteLine("mehtod of interface A"); } void IB.disp() { Console.WriteLine("method of interface B"); } } class Program { static void Main(string[] args) { B ob1 = new B(); B ob2 = new B(); IA i1 = (IA)ob1; i1.show(); IB i2 = (IB)ob2; i2.disp(); } } }

Program 26: Write a program to change the colour of Label using Radiobutton. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; public partial class Default4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (RadioButton1.Checked == true) { Label1.ForeColor = Color.Red; } else { Label1.BackColor = Color.Yellow; } } }

Program 27: Write a program to change the font of label to bold on checking the checkbox.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (CheckBox1.Checked == true) { Label1.Font.Bold = true; } else { Label1.Font.Bold = false; } } protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { } }

Program 28: Write a program to create a table on clicking a button.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { int i, j; for (i = 1; i < 5; i++) { TableRow r = new TableRow(); Table1.Controls.Add(r); for (j = 1; j < 3; j++) { TableCell cell1 = new TableCell(); Label l = new Label(); l.Text = "Label" + i + j; cell1.Controls.Add(l); r.Controls.Add(cell1); } } } }

Program 29: Write a program to implement Checkboxlist.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = "u selected"; foreach (ListItem list in CheckBoxList1.Items) { if (list.Selected == true) { Label1.Text = list.Text + "<br>"; } } } }

Program 30: Write a program to establish connection with MS-Access database.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb; public partial class Default8 : System.Web.UI.Page { OleDbCommand cmd; OleDbConnection con; protected void Page_Load(object sender, EventArgs e) {} protected void Button1_Click(object sender, EventArgs e) { try { Label1.Text= "PATH = " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb"); con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath,"dbase1. mdb")); con.Open(); Label2.Text = "Connected"; con.Close(); cmd.Dispose(); } catch{} } }

Program 31: Write a program to insert values to the MS-Access database. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb; public partial class Default8 : System.Web.UI.Page { OleDbCommand cmd; OleDbConnection con; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath,"dbase1. mdb")); con.Open(); cmd = new OleDbCommand("insert into student values(2,'Priyanka',9894887)", con); cmd.ExecuteNonQuery(); Label2.Text = "Values inserted"; con.Close(); cmd.Dispose(); } catch{} } }

Program 32: Write a program to insert the values into the database using webform. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.OleDb; using System.IO; public partial class Default2 : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; protected void Page_Load(object sender, EventArgs e) { } protected void TextBox1_TextChanged(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { int id ,ph; string sname; id = Convert.ToInt32(TextBox1.Text); sname = TextBox2.Text; ph = Convert.ToInt32(TextBox3.Text); con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("insert into student values("+id+",'"+sname+"',"+ph+")", con); cmd.ExecuteNonQuery();

Label4.Text = "values inserted"; con.Close(); cmd.Dispose(); } catch {} } }

Program 33: Write a program to fetch values from the database into a web form.

using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.OleDb; using System.IO; public partial class Default9 : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rdr; protected void Page_Load(object sender, EventArgs e) {} protected void Button1_Click(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("select * from student where id="+Convert.ToInt32(TextBox1.Text),con); rdr=cmd.ExecuteReader(); if(rdr.Read()) { TextBox1.Text=""+rdr.GetValue(0); TextBox2.Text=""+rdr.GetValue(1); TextBox3.Text=""+rdr.GetValue(2); } con.Close(); cmd.Dispose(); } catch {} }

Program 34: Write a program to fetch the maximum value of roll number from the database and then insert the corresponding details into the database for the fetched roll no.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb; public partial class Default3 : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rdr; protected void Page_Load(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("select * from entry where Roll_no=(select max(Roll_no) from entry)", con); rdr = cmd.ExecuteReader(); if (rdr.Read() == true) { int i = Convert.ToInt32(rdr.GetValue(0)); i = i + 1; TextBox1.Text = "" + i; } else { TextBox1.Text = "" + 100; } con.Close(); cmd.Dispose();

} catch {} } protected void Button1_Click(object sender, EventArgs e) { try { string sname; con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); sname = TextBox2.Text; con.Open(); cmd = new OleDbCommand("insert into entry values("+Convert.ToInt32(TextBox1.Text)+",'"+sname+"')", con); cmd.ExecuteNonQuery(); con.Close(); cmd.Dispose(); } catch {} } }

Program 35: Write a program to fetch the maximum and minimum marks from the database and display it on the web form.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb; public partial class Default7 : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rdr; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("select max(marks) from student1", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) { TextBox1.Text = "" + rdr.GetValue(0); } con.Close(); cmd.Dispose(); } catch

{} } protected void Button3_Click(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("select min(marks) from student1", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) { TextBox1.Text = "" + rdr.GetValue(0); } con.Close(); cmd.Dispose(); } catch {} } }

Program 36: Write a program to calculate the second maximum marks from the database and display on the web form.

using System; using System.Collections.Generic; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb; public partial class Default7 : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rdr; protected void Page_Load(object sender, EventArgs e) { } protected void Button4_Click(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("select max(marks) from student1 where marks < (select max(marks) from student1)", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) { TextBox1.Text = "" + rdr.GetValue(0); } con.Close(); cmd.Dispose(); } catch {} } }

Program 37: Write a program to count the number of records in the database and the display the value on the web form.

using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb; public partial class Default7 : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd; OleDbDataReader rdr; protected void Page_Load(object sender, EventArgs e) {} protected void Button2_Click(object sender, EventArgs e) { try { con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "dbase1.mdb")); con.Open(); cmd = new OleDbCommand("select count(marks) from student1", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) { TextBox1.Text = "" + rdr.GetValue(0); } con.Close(); cmd.Dispose(); } catch {} } }

Program 38: Write a program to fetch the Roll number from a table in database in a Dropdown and then on selecting a roll number, display the corresponding details on the web form.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.OleDb; using System.IO;

public partial class _Default : System.Web.UI.Page { OleDbConnection con, con1; OleDbCommand cmd, cmd1; OleDbDataReader rdr, rdr1; String rno;

protected void Page_Load(object sender, EventArgs e) { try { con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "db.mdb")); con.Open(); cmd = new OleDbCommand("select * from details", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) { DropDownList1.Items.Add("" + rdr.GetValue(0)); }

con.Close(); cmd.Dispose(); } catch { } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { rno = DropDownList1.Text; try { con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "db.mdb")); con.Open(); cmd = new OleDbCommand("select * from details where rno = '" + rno + "' ", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Label1.Text = "" + rdr.GetValue(1); Label2.Text = "" + rdr.GetValue(2); Label3.Text = "" + rdr.GetValue(3); } con.Close(); cmd.Dispose(); } catch { } } }

Program 39: Write a program to fetch the values in multiple Dropdown lists and on selecting any value from any of the Dropdown list, display that corresponding value in the textbox.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page { OleDbConnection con; OleDbCommand cmd,cmd1,cmd2; OleDbDataReader rdr,rdr1,rdr2; String s;

protected void Page_Load(object sender, EventArgs e) { try { con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "sdb.mdb")); con.Open();

cmd = new OleDbCommand("select * from sdb", con); cmd1 = new OleDbCommand("select distinct name from sdb", con); cmd2 = new OleDbCommand("select distinct address from sdb", con); rdr = cmd.ExecuteReader(); rdr1 = cmd1.ExecuteReader(); rdr2 = cmd2.ExecuteReader();

while (rdr.Read()) { DropDownList1.Items.Add("" + rdr.GetValue(0)); } while (rdr1.Read()) { DropDownList2.Items.Add("" + rdr1.GetValue(0)); } while (rdr2.Read()) { DropDownList3.Items.Add("" + rdr2.GetValue(0)); } con.Close(); cmd.Dispose(); } catch { } } protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e) { try { s = DropDownList3.Text; con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "sdb.mdb")); con.Open(); cmd = new OleDbCommand("select * from sdb where address = '"+s+"'", con); rdr = cmd.ExecuteReader(); while (rdr.Read()) {

} con.Close(); cmd.Dispose(); } catch { } TextBox1.Text = DropDownList3.Text; } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { TextBox1.Text = DropDownList2.Text; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { TextBox1.Text = DropDownList1.Text; } protected void TextBox1_TextChanged(object sender, EventArgs e) { } }

Program 40: Write a program to implement a simple calculator.

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { static int n; static int x; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { TextBox2.Text = Button1.Text; } protected void Button15_Click(object sender, EventArgs e) { TextBox2.Text = Button15.Text; } protected void Button2_Click(object sender, EventArgs e) { TextBox2.Text = Button2.Text; } protected void Button3_Click(object sender, EventArgs e) { TextBox2.Text = Button3.Text; } protected void Button4_Click(object sender, EventArgs e) { TextBox2.Text = Button4.Text;

} protected void Button5_Click(object sender, EventArgs e) { TextBox2.Text = Button5.Text; } protected void Button6_Click(object sender, EventArgs e) { TextBox2.Text = Button6.Text; } protected void Button7_Click(object sender, EventArgs e) { TextBox2.Text = Button7.Text; } protected void Button8_Click(object sender, EventArgs e) { TextBox2.Text = Button8.Text; } protected void Button9_Click(object sender, EventArgs e) { TextBox2.Text = Button9.Text; } protected void Button11_Click(object sender, EventArgs e) { n = Convert.ToInt32(TextBox2.Text); x = 1; } protected void Button12_Click(object sender, EventArgs e) { n = Convert.ToInt32(TextBox2.Text); x = 2; } protected void Button13_Click(object sender, EventArgs e) { n = Convert.ToInt32(TextBox2.Text); x = 3; } protected void Button14_Click(object sender, EventArgs e) { n = Convert.ToInt32(TextBox2.Text); x = 4; } protected void Button10_Click(object sender, EventArgs e) {

switch (x) { case 1: TextBox2.Text = "" + (n + Convert.ToInt32(TextBox2.Text)); break; case 2: TextBox2.Text = "" + (n - Convert.ToInt32(TextBox2.Text)); break; case 3: TextBox2.Text = "" + (n * Convert.ToInt32(TextBox2.Text)); break; case 4: TextBox2.Text = "" + (n / Convert.ToInt32(TextBox2.Text)); break; } } }

Program 41: Write a program to implement calendar control.

using System; using System.Collections; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing; public partial class _Default : System.Web.UI.Page { static int i;

ArrayList name = new ArrayList(); ArrayList day = new ArrayList(); ArrayList month = new ArrayList(); ArrayList year = new ArrayList(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) {

name.Add(TextBox4.Text); year.Add(TextBox3.Text); month.Add(TextBox2.Text); day.Add(TextBox1.Text); } protected void TextBox4_TextChanged(object sender, EventArgs e) {

} protected void TextBox1_TextChanged(object sender, EventArgs e) { } protected void TextBox2_TextChanged(object sender, EventArgs e) { } protected void TextBox3_TextChanged(object sender, EventArgs e) { } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { } protected void Calendar1_DayRender1(object sender, DayRenderEventArgs e) { for (i = 0; i < name.Count; i++) { if (e.Day.Date.Day == Convert.ToInt32(day[i]) && e.Day.Date.Month == Convert.ToInt32(month[i]) && e.Day.Date.Year == Convert.ToInt32(year[i])) { e.Cell.BackColor = Color.Blue; Label l1 = new Label(); l1.Text = "<br>" + name[i] + "" + day[i] + "" + month[i] + "" + year[i] + "<br>"; e.Cell.Controls.Add(l1); } } } }

Program 42: Write a program to change the colour of label using checkbox.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (CheckBox1.Checked == true) { Label1.ForeColor = Color.Red; } if(CheckBox2.Checked==true) { Label1.ForeColor=Color.Green; } } }

Program 43: Write a program to implement Radiobutton list.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = "You have selected:" + RadioButtonList1.Text; } }

Program 44: Write a program to implement Dropdownlist.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; public partial class Default7 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { if (DropDownList1.SelectedIndex == 0) { Label1.ForeColor = Color.Red; } if (DropDownList1.SelectedIndex == 1) { Label1.ForeColor = Color.Blue; } } }

You might also like