· 7 years ago · Oct 25, 2018, 05:24 AM
1Practical No.1
2Create an application that obtains four int values from the user and displays the product.
3
4Code:
5using System;
6using System.Collections.Generic;
7using System.Linq;
8using System.Text;
9
10namespace Practical1a.Product4Num
11{
12 class Product4Num
13 {
14 static void Main(string[] args)
15 {
16 int num1, num2, num3, num4, prod;
17 Console.Write("Enter 1st number: ");
18 num1 = Int32.Parse(Console.ReadLine());
19 Console.Write("Enter 2nd number: ");
20 num2 = Convert.ToInt32(Console.ReadLine());
21 Console.Write("Enter 3rd number: ");
22 num3 = Convert.ToInt32(Console.ReadLine());
23 Console.Write("Enter 4th number: ");
24 num4 = Convert.ToInt32(Console.ReadLine());
25 prod = num1 * num2 * num3 * num4;
26 Console.WriteLine(num1 + "*" + num2 + "*" + num3 + "*" + num4 + "=" + prod);
27 Console.ReadLine();
28 }
29 }
30}
31Output:
32Create an application to demonstrate string operations.
33Code:
34using System;
35using System.Collections.Generic;
36using System.Linq;
37using System.Text;
38
39namespace Practical1b.StringOperation
40{
41 class StringOprations
42 {
43 static void Main(string[] args)
44 {
45 string firstname;
46 string lastname;
47
48
49 firstname = "Steven Clark";
50 lastname = "Clark";
51
52
53 Console.WriteLine(firstname.Clone());
54 // Make String Clone
55
56 Console.WriteLine(firstname.CompareTo(lastname));
57 //Compare two string value and returns 0 for true and 1 for false
58
59 Console.WriteLine(firstname.Contains("ven"));
60 //Check whether specified value exists or not in string
61
62 Console.WriteLine(firstname.EndsWith("n"));
63 //Check whether specified value is the last character of string
64
65 Console.WriteLine(firstname.Equals(lastname));
66 //Compare two string and returns true and false
67
68 Console.WriteLine(firstname.GetHashCode());
69 //Returns HashCode of String
70
71 Console.WriteLine(firstname.GetType());
72 //Returns type of string
73
74 Console.WriteLine(firstname.GetTypeCode());
75 //Returns type of string
76
77 Console.WriteLine(firstname.IndexOf("e")); //Returns the first index
78 position of specified value the first index position of specified value
79
80 Console.WriteLine(firstname.ToLower());
81 //Covert string into lower case
82
83 Console.WriteLine(firstname.ToUpper());
84 //Convert string into Upper case
85
86 Console.WriteLine(firstname.Insert(0, "Hello")); //Insert substring into
87 string
88
89 Console.WriteLine(firstname.IsNormalized());
90 //Check Whether string is in Unicode normalization from C
91
92 Console.WriteLine(firstname.LastIndexOf("e")); //Returns the last index
93 position of specified value
94
95 Console.WriteLine(firstname.Length);
96 //Returns the Length of String
97
98 Console.WriteLine(firstname.Remove(5));
99 //Deletes all the characters from begining to specified index.
100
101 Console.WriteLine(firstname.Replace('e','i')); // Replace the character
102
103 string[] split = firstname.Split(new char[] { 'e' }); //Split the string
104 based on specified value
105
106
107 Console.WriteLine(split[0]);
108 Console.WriteLine(split[1]);
109 Console.WriteLine(split[2]);
110
111 Console.WriteLine(firstname.StartsWith("S")); //Check whether first
112 character of string is same as specified value
113
114 Console.WriteLine(firstname.Substring(2,5));
115 //Returns substring
116
117 Console.WriteLine(firstname.ToCharArray());
118 //Converts an string into char array.
119
120 Console.WriteLine(firstname.Trim());
121 //It removes starting and ending white spaces from string.
122
123 Console.ReadLine();
124
125 }
126 }
127}
128
129
130Output:
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162Create an application that receives the (Student Id, Student Name, Course Name, Date of Birth) information from a set of students. The application should also display the information of all the students once the data entered.
163
164Code:
165
166using System;
167using System.Collections.Generic;
168using System.Linq;
169using System.Text;
170
171namespace Practical1c.StudentInfo
172{
173 class Program
174 {
175 struct Student
176 {
177 public string studid, name, cname;
178 public int day, month, year;
179 }
180
181 static void Main(string[] args)
182 {
183 Student[] s = new Student[5];
184 int i;
185 for (i = 0; i < 5; i++)
186 {
187 Console.Write("Enter Student Id:");
188 s[i].studid = Console.ReadLine();
189 Console.Write("Enter Student name : ");
190 s[i].name = Console.ReadLine();
191 Console.Write("Enter Course name : ");
192 s[i].cname = Console.ReadLine();
193 Console.Write("Enter date of birth\n Enter day(1-31):");
194 s[i].day = Convert.ToInt32(Console.ReadLine());
195 Console.Write("Enter month(1-12):");
196 s[i].month = Convert.ToInt32(Console.ReadLine());
197 Console.Write("Enter year:");
198 s[i].year = Convert.ToInt32(Console.ReadLine());
199 }
200 Console.WriteLine("\n\nStudent's List\n");
201 for (i = 0; i < 5; i++)
202 {
203 Console.WriteLine("\nStudent ID : " + s[i].studid);
204 Console.WriteLine("\nStudent name : " + s[i].name);
205 Console.WriteLine("\nCourse name : " + s[i].cname);
206 Console.WriteLine("\nDate of birth(dd-mm-yy) : " + s[i].day + "-" + s[i].month + "-" + s[i].year);
207 }
208 Console.ReadLine();
209 }
210 }
211}
212
213Output:
214
215
216Create an application to demonstrate following operations
217Generate Fibonacci series.
218
219Code:
220using System;
221using System.Collections.Generic;
222using System.Linq;
223using System.Text;
224
225namespace Practical1d.Febonacci
226{
227 class Fibonacci
228 {
229 public static void Main(String[] args)
230 {
231 int firstnum = 0, secondnum = 1, count = 0, nterms, fibo;
232 Console.WriteLine("Enter the range of fibonacci serise:");
233 nterms = Convert.ToInt32(Console.ReadLine());
234 if (nterms <= 0)
235 {
236 Console.WriteLine("Please enter a positive Integer!!");
237 }
238 else if (nterms == 1)
239 {
240 Console.WriteLine("Febonacci series up to " + nterms + ":");
241 Console.WriteLine(firstnum);
242 }
243 else
244 {
245 Console.WriteLine("Febonacci series up to " + nterms + ":");
246 while (count < nterms)
247 {
248 Console.WriteLine(firstnum + ",");
249 fibo = firstnum + secondnum;
250 firstnum = secondnum;
251 secondnum = fibo;
252 count = count + 1;
253 }
254 }
255 Console.ReadLine();
256 }
257 }
258}
259
260
261
262
263Output:
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282Test For Prime Numbers
283Code:
284using System;
285using System.Collections.Generic;
286using System.Linq;
287using System.Text;
288
289namespace Practical1d1.Prime
290{
291 class PrimeNumber
292 {
293 public static void Main(String [] args)
294 {
295 int i,num,flag=0;
296 Console.WriteLine("Enter the number:");
297 num=Convert.ToInt32(Console.ReadLine());
298 for(i=2;i<=num/2;i++)
299 {
300 if(num%i==0)
301 {
302 flag=1;
303 break;
304 }
305 }
306 if(flag==0)
307 {
308 Console.WriteLine("The entered number is Prime number:");
309 }
310 else
311 {
312 Console.WriteLine("The entered number is not Prime number:");
313 }
314 }
315 }
316}
317
318Output:
319
320Test For Vowels
321Code:
322using System;
323using System.Collections.Generic;
324using System.Linq;
325using System.Text;
326
327namespace Practical1d3
328{
329 class Vowel
330 {
331 static void Main(string[] args)
332 {
333 char ch;
334 Console.Write("Enter a character : ");
335 ch = (char)
336 Console.Read();
337 switch (ch)
338 {
339 case 'a':
340 case 'A':
341 case 'e':
342 case 'E':
343 case 'i':
344 case 'I':
345 case 'o':
346 case 'O':
347 case 'u':
348 case 'U':
349 Console.WriteLine(ch + " is vowel");
350 break;
351 default:
352 Console.Write(ch + " is not a vowel");
353 break;
354 }
355 Console.ReadKey();
356 }
357 }
358}
359
360Output:
361
362Use of foreach loop with Arrays
363Code:
364using System;
365using System.Collections.Generic;
366using System.Linq;
367using System.Text;
368
369namespace Practical1d4
370{
371 class Foreachloop
372 {
373 public static void Main()
374 {
375 string[] str = { "Shield", "Evaluation", "DX" };
376 foreach (String s in str)
377 {
378 Console.WriteLine(s);
379 }
380 Console.ReadLine();
381 }
382 }
383}
384
385Output:
386
387
388
389
390
391Reverse a number and find sum of digit of a number
392Code:
393using System;
394using System.Collections.Generic;
395using System.Linq;
396using System.Text;
397
398namespace Practical1d5
399{
400 class ReverseSum
401 {
402 static void Main(string[] args)
403 {
404 int num, actualnumber, revnum = 0, digit, sumDigits = 0;
405 Console.Write("Enter number:");
406 num = int.Parse(Console.ReadLine());
407 actualnumber = num;
408 while (num > 0)
409 {
410 digit = num % 10;
411 revnum = revnum * 10 + digit;
412 sumDigits = sumDigits + digit;
413 num = num / 10;
414 }
415 Console.WriteLine("Reverse of " + actualnumber + "=" + revnum);
416 Console.WriteLine("Sum of its digits:" + sumDigits);
417 Console.ReadLine();
418 }
419 }
420}
421Output:
422
423Practical No.2
424Create a simple application to demonstrate fallowing operations.
425Finding Factorial Value
426Code:
427using System;
428using System.Collections.Generic;
429using System.Linq;
430using System.Text;
431
432namespace Project1
433{
434 class Factorial
435 {
436 public static void Main(string[] args)
437 {
438 int i, fact = 1, number;
439 Console.Write("Enter any Number: ");
440 number = int.Parse(Console.ReadLine());
441 for (i = 1; i <= number; i++)
442 {
443 fact = fact * i;
444 }
445 Console.Write("Factorial of " + number + " is: " + fact);
446 Console.ReadLine();
447 }
448 }
449}
450
451Output:
452
453Money Conversion
454Code:
455using System;
456using System.Collections.Generic;
457using System.Linq;
458using System.Text;
459
460namespace Practical2a2
461{
462 class MoneyConverter
463 {
464 static void Main(string[] args)
465 {
466 int choice;
467 Console.WriteLine("Enter your Choice :\n 1- Dollar to Rupee \n 2- Euro to Rupee \n 3- Malaysian Ringgit to Rupee ");
468 choice = int.Parse(Console.ReadLine());
469 switch (choice)
470 {
471 case 1:
472 Double dollar, rupee, val;
473 Console.WriteLine("Enter the Dollar Amount :");
474 dollar = Double.Parse(Console.ReadLine());
475 Console.WriteLine("Enter the Dollar Value :");
476 val = double.Parse(Console.ReadLine());
477 rupee = dollar * val;
478 Console.WriteLine("{0} Dollar Equals {1} Rupees", dollar, rupee);
479 break;
480 case 2:
481 Double Euro, rupe, valu;
482 Console.WriteLine("Enter the Euro Amount :");
483 Euro = Double.Parse(Console.ReadLine());
484 Console.WriteLine("Enter the Euro Value :");
485 valu = double.Parse(Console.ReadLine());
486 rupe = Euro * valu;
487 Console.WriteLine("{0} Euro Equals {1} Rupees", Euro, rupe);
488 break;
489 case 3:
490 Double ringit, rup, value;
491 Console.WriteLine("Enter the Ringgit Amount :");
492 ringit = Double.Parse(Console.ReadLine());
493 Console.WriteLine("Enter the Ringgit Value :");
494 value = double.Parse(Console.ReadLine());
495 rup = ringit * value;
496 Console.WriteLine("{0} Malaysian Ringgit Equals {1} Rupees", ringit, rup);
497 break;
498 }
499 Console.ReadLine();
500 }
501 }
502}
503
504Output:
505
506
507
508Quadratic Equation
509
510Code:
511
512using System;
513using System.Collections.Generic;
514using System.Linq;
515using System.Text;
516
517namespace Practical2a3
518{
519 class QuadraticEquation
520 {
521 public static void Main()
522 {
523 int a, b, c;
524
525 double d, x1, x2;
526 Console.Write("\n\n");
527 Console.Write("Calculate root of Quadratic Equation :\n");
528 Console.Write("----------------------------------------");
529 Console.Write("\n\n");
530
531 Console.Write("Input the value of a : ");
532 a = Convert.ToInt32(Console.ReadLine());
533 Console.Write("Input the value of b : ");
534 b = Convert.ToInt32(Console.ReadLine());
535 Console.Write("Input the value of c : ");
536 c = Convert.ToInt32(Console.ReadLine());
537
538 d = b * b - 4 * a * c;
539 if (d == 0)
540 {
541 Console.Write("Both roots are equal.\n");
542 x1 = -b / (2.0 * a);
543 x2 = x1;
544 Console.Write("First Root Root1= {0}\n", x1);
545 Console.Write("Second Root Root2= {0}\n", x2);
546 }
547 else if (d > 0)
548 {
549 Console.Write("Both roots are real and diff-2\n");
550
551 x1 = (-b + Math.Sqrt(d)) / (2 * a);
552 x2 = (-b - Math.Sqrt(d)) / (2 * a);
553
554 Console.Write("First Root Root1= {0}\n", x1);
555 Console.Write("Second Root root2= {0}\n", x2);
556 }
557 else
558 Console.Write("Root are imeainary;\nNo Solution. \n\n");
559 Console.ReadLine();
560 }
561 }
562}
563
564Output:
565
566
567Temperature Conversion
568Code:
569using System;
570using System.Collections.Generic;
571using System.Linq;
572using System.Text;
573
574namespace TemperatureControl
575{
576 class TemperatureConverter
577 {
578 static void Main(string[] args)
579 {
580 int celsius, faren;
581 Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
582 celsius = int.Parse(Console.ReadLine());
583 faren = (celsius * 9) / 5 + 32;
584 Console.WriteLine("0Temperature in Fahrenheit is(°F) : " + faren);
585 Console.ReadLine();
586
587 }
588 }
589}
590
591Output:
592
593
594
595Create a simple application to demonstrate use of following concepts.
596Function Overloading
597Code:
598using System;
599using System.Collections.Generic;
600using System.Linq;
601using System.Text;
602
603namespace Practical2b1
604{
605 class FunctionOverLoading
606 {
607 // adding two integer values.
608 public int Add(int a, int b)
609 {
610 int sum = a + b;
611 return sum;
612 }
613
614 // adding three integer values.
615 public int Add(int a, int b, int c)
616 {
617 int sum = a + b + c;
618 return sum;
619 }
620
621 // Main Method
622 public static void Main(String[] args)
623 {
624
625 // Creating Object
626 FunctionOverLoading ob = new FunctionOverLoading();
627
628 int sum1 = ob.Add(1, 2);
629 Console.WriteLine("sum of the two "
630 + "integer value : " + sum1);
631
632 int sum2 = ob.Add(1, 2, 3);
633 Console.WriteLine("sum of the three "
634 + "integer value : " + sum2);
635 Console.ReadLine();
636 }
637 }
638}
639
640
641Output:
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659Inheritance
660Single Inheritance
661Code:
662using System;
663using System.Collections.Generic;
664using System.Linq;
665using System.Text;
666
667namespace Practical2b1
668{
669 class SingleInheritance
670 {
671 static void Main(string[] args)
672 {
673 Teacher d = new Teacher();
674 d.Teach();
675 Student s = new Student();
676 s.Learn();
677 s.Teach();
678 Console.ReadKey();
679 }
680 class Teacher
681 {
682 public void Teach()
683 {
684 Console.WriteLine("Teaches the Students");
685 }
686 }
687 class Student : Teacher
688 {
689 public void Learn()
690 {
691 Console.WriteLine("Student’s learn from Teachers");
692 }
693 }
694 }
695}
696
697
698
699
700
701
702
703Output:
704
705Multilevel Inheritance
706Code:
707using System;
708using System.Collections.Generic;
709using System.Linq;
710using System.Text;
711
712namespace Practical2b2
713{
714 class MultilevelInheritance : vehicle
715 {
716 public void Noise()
717 {
718 Console.WriteLine("All Vehicles Creates Noise !! ");
719 }
720 static void Main(string[] args)
721 {
722 MultilevelInheritance obj = new MultilevelInheritance();
723 obj.mode();
724 obj.feature();
725 obj.Noise();
726 Console.Read();
727 }
728 }
729 class Mode
730 {
731 public void mode()
732 {
733 Console.WriteLine("There are Many Modes of Transport !!");
734 }
735 }
736 class vehicle : Mode
737 {
738 public void feature()
739 {
740 Console.WriteLine("They Mainly Help in Travelling !!");
741 }
742 }
743}
744
745Output:
746
747Hierarchical Inheritance
748Code:
749using System;
750using System.Collections.Generic;
751using System.Linq;
752using System.Text;
753
754namespace Practical2b23
755{
756 class HierarchicalInheritance
757 {
758 static void Main(string[] args)
759 {
760 Principal g = new Principal();
761 g.Monitor();
762 Teacher d = new Teacher();
763 d.Monitor();
764 d.Teach();
765 Student s = new Student();
766 s.Monitor();
767 s.Learn();
768 Console.ReadKey();
769 }
770 class Principal
771 {
772 public void Monitor()
773 {
774 Console.WriteLine("Principal monitor's the staff");
775 }
776 }
777 class Teacher : Principal
778 {
779 public void Teach()
780 {
781 Console.WriteLine("Teacher teaches the class");
782 }
783 }
784 class Student : Principal
785 {
786 public void Learn()
787 {
788 Console.WriteLine("Students learn from Teachers");
789 }
790 }
791 }
792}
793
794Output:
795
796Hybrid Inheritance
797Code:
798using System;
799using System.Collections.Generic;
800using System.Linq;
801using System.Text;
802
803namespace Hybrid
804{
805 class HybridInheritance
806 {
807 static void Main(string[] args)
808 {
809 Principal g = new Principal();
810 g.Monitor();
811 Teacher d = new Teacher();
812 d.Monitor();
813 d.Teach();
814 Student s = new Student();
815 s.Monitor();
816 s.Learn();
817 Nonteaching n = new Nonteaching();
818 n.Service();
819 Console.ReadKey();
820 }
821 class Principal
822 {
823 public void Monitor()
824 {
825 Console.WriteLine("Principal monitor's the staff");
826 }
827 }
828 class Teacher : Principal
829 {
830 public void Teach()
831 {
832 Console.WriteLine("Teacher teaches the class");
833 }
834 }
835 class Student : Principal
836 {
837 public void Learn()
838 {
839 Console.WriteLine("Students learn from Teachers");
840 }
841 }
842 class Nonteaching : Teacher
843 {
844 public void Service()
845 {
846 Console.WriteLine("Provides services");
847 }
848 }
849 }
850}
851
852
853Output:
854
855
856
857
858
859
860
861
862
863
864
865
866
867Constructor Overloading
868Code:
869using System;
870using System.Collections.Generic;
871using System.Linq;
872using System.Text;
873
874namespace ConstructorOver
875{
876 class GameScore
877 {
878 string user;
879 int age;
880 //Default Constructor
881 public GameScore()
882 {
883 user = "Steven";
884 age = 28;
885 Console.WriteLine("Previous User {0} and he was {1} year old", user, age);
886 }
887
888 //Parameterized Constructor
889 public GameScore(string name, int age1)
890 {
891 user = name;
892 age = age1;
893 Console.WriteLine("Current User {0} and he is {1} year old", user, age);
894 }
895 }
896
897 class Program
898 {
899 static void Main(string[] args)
900 {
901 GameScore gs = new GameScore(); //Default Constructor Called
902 GameScore gs1 = new GameScore("Clark", 35); //Overloaded Constructor.
903 Console.ReadLine();
904 }
905 }
906}
907
908
909
910
911
912
913
914
915Output:
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936Interfaces
937Code:
938using System;
939using System.Collections.Generic;
940using System.Linq;
941using System.Text;
942
943namespace Interface1
944{
945 interface ITransactions
946 {
947 // interface members
948 void show Transaction();
949 double getAmount();
950 }
951 public class Transaction : ITransactions {
952 private string tCode;
953 private string date;
954 private double amount;
955
956 public Transaction() {
957 tCode = " ";
958 date = " ";
959 amount = 0.0;
960 }
961 public Transaction(string c, string d, double a) {
962 tCode = c;
963 date = d;
964 amount = a;
965 }
966 public double getAmount() {
967 return amount;
968 }
969 public void showTransaction() {
970 Console.WriteLine("Transaction: {0}", tCode);
971 Console.WriteLine("Date: {0}", date);
972 Console.WriteLine("Amount: {0}", getAmount());
973 }
974 }
975 class Tester {
976
977 static void Main(string[] args) {
978 Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);
979 Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);
980
981 t1.showTransaction();
982 t2.showTransaction();
983 Console.ReadKey();
984 }
985 }
986}
987
988Output:
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004Create a simple application to demonstrate the following concepts.
1005Using Delegates and Events
1006Code:
1007using System;
1008using System.Collections.Generic;
1009using System.Linq;
1010using System.Text;
1011
1012namespace Delegates
1013{
1014 public delegate void TrafficDel();
1015 class Delegates
1016 {
1017
1018 public static void Yellow()
1019 {
1020 Console.WriteLine("Yellow light signals to get ready");
1021 }
1022 public static void Green()
1023 {
1024 Console.WriteLine("Green light signals to go");
1025 }
1026 public static void Red()
1027 {
1028 Console.WriteLine("Red light signals to stop");
1029 }
1030 TrafficDel[] td = new TrafficDel[3];
1031 public void IdentifySignal()
1032 {
1033 td[0] = new TrafficDel(Yellow);
1034 td[1] = new TrafficDel(Green);
1035 td[2] = new TrafficDel(Red);
1036 }
1037 public void display()
1038 {
1039 td[0]();
1040 td[1]();
1041 td[2]();
1042 }
1043 }
1044 class Program
1045 {
1046 static void Main(string[] args)
1047 {
1048 Delegates ts = new Delegates();
1049 ts.IdentifySignal();
1050 ts.display();
1051 Console.ReadLine();
1052 }
1053 }
1054}
1055
1056Output:
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073Exception Handling
1074Code:
1075using System;
1076using System.Collections.Generic;
1077using System.Linq;
1078using System.Text;
1079
1080namespace ExceptionHandlingEx
1081{
1082 class ExceptionHandeling
1083 {
1084 static void Main(string[] args)
1085 {
1086 int num;
1087 try
1088 {
1089 Console.Write("Enter a number: ");
1090 num = int.Parse(Console.ReadLine());
1091 if ((num % 2) != 0) throw new NotEvenException("Not an even number ");
1092 else
1093 Console.WriteLine("Its even number ");
1094 }
1095 catch (NotEvenException e) { Console.WriteLine(e.Message); }
1096 Console.ReadLine();
1097 }
1098 }
1099 class NotEvenException : Exception
1100 {
1101 public NotEvenException(string msg)
1102 : base(msg)
1103 {
1104 }
1105 }
1106}
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121Output:
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137Practical No.3
1138Create a simple web page with various sever controls to demonstrate setting and use of their properties. (Example : AutoPostBack)
1139
1140Code:
1141
1142WebForm.aspx
1143
1144<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Practical3a.WebForm1" %>
1145
1146<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1147
1148<html xmlns="http://www.w3.org/1999/xhtml">
1149<head runat="server">
1150 <title></title>
1151 <style type="text/css">
1152 .style1
1153 {
1154 width : 100%;
1155 }
1156 .style2
1157 {
1158 width : 153px;
1159 }
1160 .style3
1161 {
1162 width : 153px;
1163 width : 26px;
1164 }
1165 .style4
1166 {
1167 height :26px;
1168 }
1169 </style>
1170
1171</head>
1172<body>
1173 <form id="form1" runat="server">
1174 <div>
1175 <table class="style1">
1176 <tr>
1177 <td class="style2">
1178 <asp:Label ID="Label1" runat="server" Text="Rno"></asp:Label>
1179 </td>
1180 <td>
1181 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
1182 </td>
1183 </tr>
1184 <tr>
1185 <td class="style2">
1186 <asp:Label ID="Label2" runat="server" Text="Name"></asp:Label>
1187 </td>
1188 <td>
1189 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
1190 </td>
1191 </tr>
1192 <tr>
1193 <td class="style2">
1194 <asp:Label ID="Label3" runat="server" Text="Class"></asp:Label>
1195 </td>
1196 <td>
1197 <asp:RadioButton ID="RadioButton1" runat="server" Text="FY"/>
1198 <asp:RadioButton ID="RadioButton2" runat="server" Text="SY"/>
1199 <asp:RadioButton ID="RadioButton3" runat="server" Text="TY"/>
1200 </td>
1201 </tr>
1202 <tr>
1203 <td class="style3">
1204 <asp:Label ID="Label4" runat="server" Text="Course"></asp:Label>
1205 </td>
1206 <td class="style4">
1207 <asp:DropDownList ID="DropDdownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged1">
1208 <asp:ListItem>B.Com</asp:ListItem>
1209 <asp:ListItem>BMS</asp:ListItem>
1210 <asp:ListItem>B.SC(IT)</asp:ListItem>
1211 <asp:ListItem>B.SC(CS)</asp:ListItem>
1212 </asp:DropDownList>
1213 </td>
1214 </tr>
1215 <tr>
1216 <td class="style3">
1217
1218 </td>
1219 <td class="style4">
1220 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"/>
1221 </td>
1222 </tr>
1223 </table>
1224 </div>
1225 <asp:label ID="Label5" runat="server" Text="Label"></asp:label>
1226 </form>
1227</body>
1228</html>
1229
1230
1231
1232WebForm.aspx.cs
1233
1234using System;
1235using System.Collections.Generic;
1236using System.Linq;
1237using System.Web;
1238using System.Web.UI;
1239using System.Web.UI.WebControls;
1240
1241namespace Practical3a
1242{
1243 public partial class WebForm1 : System.Web.UI.Page
1244 {
1245 protected void Page_Load(object sender, EventArgs e)
1246 {
1247
1248 }
1249 protected void Button1_Click(object sender, EventArgs e)
1250 {
1251 string s;
1252 if(RadioButton1.Checked==true)
1253 {
1254 s = RadioButton1.Text;
1255 }
1256 else if(RadioButton2.Checked==true)
1257 s=RadioButton2.Text;
1258 else
1259 s=RadioButton3.Text;
1260 Label5.Text+=" in "+s;
1261 }
1262 protected void DropDownList1_SelectedIndexChanged1(object sender,EventArgs e)
1263 {
1264 Label5.Text="You have been enrolled in "+ DropDdownList1.SelectedIndex;
1265 }
1266 }
1267}
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282Output:
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313Demonstrate the use of Calendar control to perform following operations.
1314Display messages in a calendar control
1315Display vacation in a calendar control
1316Selected day in a calendar control using style
1317Difference between two calendar dates
1318
1319Code:
1320
1321Calender.aspx
1322
1323<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Calender.aspx.cs" Inherits="Calender.Calender.Calender" %>
1324
1325<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1326
1327<html xmlns="http://www.w3.org/1999/xhtml">
1328<head runat="server">
1329 <title></title>
1330</head>
1331<body>
1332 <form id="form1" runat="server">
1333 <div>
1334
1335 <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
1336 BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
1337 Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
1338 onselectionchanged="Calendar1_SelectionChanged" ShowGridLines="True"
1339 Width="220px">
1340 <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
1341 <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
1342 <OtherMonthDayStyle ForeColor="#CC9966" />
1343 <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
1344 <SelectorStyle BackColor="#FFCC66" />
1345 <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
1346 ForeColor="#FFFFCC" />
1347 <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
1348 </asp:Calendar>
1349 <br />
1350 <asp:Button ID="Button1" runat="server" Text="Result" onclick="btnResult_Click"/>
1351 <br />
1352 <asp:Button ID="Button2" runat="server" Text="Reset" onclick="btnReset_Click"/>
1353 <br />
1354 <br />
1355 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
1356 <br />
1357 <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
1358 <br />
1359 <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
1360 <br />
1361 <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
1362 <br />
1363 <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
1364
1365 </div>
1366 </form>
1367</body>
1368</html>
1369
1370Calendar.aspx.cs
1371
1372using System;
1373using System.Collections.Generic;
1374using System.Linq;
1375using System.Web;
1376using System.Web.UI;
1377using System.Web.UI.WebControls;
1378
1379namespace Calander.Calander
1380{
1381 public partial class Calander : System.Web.UI.Page
1382 {
1383 protected void Page_Load(object sender, EventArgs e)
1384 {
1385
1386 }
1387 protected void btnResult_Click(object sender, EventArgs e)
1388 {
1389 Calendar1.Caption = "SAMBARE";
1390 Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
1391 Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
1392 Calendar1.TitleFormat = TitleFormat.Month;
1393 Label2.Text = "Todays Date" + Calendar1.TodaysDate.ToShortDateString();
1394 Label3.Text = "Ganpati Vacation Start: 9-13-2018";
1395 TimeSpan d = new DateTime(2018, 9, 13) - DateTime.Now;
1396 Label4.Text = "Days Remaining For Ganpati Vacation:" + d.Days.ToString();
1397 TimeSpan d1 = new DateTime(2018, 12, 31) - DateTime.Now;
1398 Label5.Text = "Days Remaining for New Year:" + d1.Days.ToString();
1399 if (Calendar1.SelectedDate.ToShortDateString() == "9-13-2018")
1400 Label3.Text = "<b>Ganpati Festival Start</b>";
1401 if (Calendar1.SelectedDate.ToShortDateString() == "9-23-2018")
1402 Label3.Text = "<b>Ganpati Festival End</b>";
1403 }
1404 protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
1405 {
1406 if (e.Day.Date.Day == 5 && e.Day.Date.Month == 9)
1407 {
1408 e.Cell.BackColor = System.Drawing.Color.Yellow;
1409 Label lbl = new Label();
1410 lbl.Text = "<br>Teachers Day!";
1411 e.Cell.Controls.Add(lbl);
1412 Image g1 = new Image();
1413 g1.ImageUrl = "td.jpg";
1414 g1.Height = 20;
1415 g1.Width = 20;
1416 e.Cell.Controls.Add(g1);
1417 }
1418 if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
1419 {
1420 Calendar1.SelectedDate = new DateTime(2018, 9, 12);
1421 Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate, Calendar1.SelectedDate.AddDays(10));
1422 Label lbl1 = new Label();
1423 lbl1.Text = "<br>Ganpati!";
1424 e.Cell.Controls.Add(lbl1);
1425 }
1426 }
1427 protected void btnReset_Click(object sender, EventArgs e)
1428 {
1429 Label1.Text = "";
1430 Label2.Text = "";
1431 Label3.Text = "";
1432 Label4.Text = "";
1433 Label5.Text = "";
1434 Calendar1.SelectedDates.Clear();
1435 }
1436 protected void Calendar1_SelectionChanged(object sender, EventArgs e)
1437 {
1438 Label1.Text = "Your Selected Date:" + Calendar1.SelectedDate.Date.ToString();
1439 }
1440 }
1441}
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452Output:
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462Practical No.4
1463Create a Registration form to demonstrate use of various Validation controls.
1464Code:
1465<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidForm.aspx.cs" Inherits="validationForm.ValidationForm.ValidForm" %>
1466
1467<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1468
1469<html xmlns="http://www.w3.org/1999/xhtml" >
1470<head id="Head1" runat="server">
1471 <title>Order Form</title>
1472</head>
1473<body>
1474 <form id="form1" runat="server">
1475 <div>
1476
1477 <fieldset>
1478 <legend>Product Order Form</legend>
1479
1480 <asp:Label
1481 id="lblProductName"
1482 Text="Product Name:"
1483 AssociatedControlID="txtProductName"
1484 Runat="server" />
1485 <br />
1486 <asp:TextBox
1487 id="txtProductName"
1488 Runat="server" />
1489 <asp:RequiredFieldValidator
1490 id="reqProductName"
1491 ControlToValidate="txtProductName"
1492 Text="(Required)"
1493 Runat="server" />
1494
1495 <br /><br />
1496
1497 <asp:Label
1498 id="lblProductPrice"
1499 Text="Product Price:"
1500 AssociatedControlID="txtProductPrice"
1501 Runat="server" />
1502 <br />
1503 <asp:TextBox
1504 id="txtProductPrice"
1505 Columns="5"
1506 Runat="server" />
1507 <asp:RequiredFieldValidator
1508 id="reqProductPrice"
1509 ControlToValidate="txtProductPrice"
1510 Text="(Required)"
1511 Display="Dynamic"
1512 Runat="server" />
1513 <asp:CompareValidator
1514 id="cmpProductPrice"
1515 ControlToValidate="txtProductPrice"
1516 Text="(Invalid Price)"
1517 Operator="DataTypeCheck"
1518 Type="Currency"
1519 Runat="server" />
1520
1521 <br /><br />
1522 <asp:Label
1523 id="lblProductQuantity"
1524 Text="Product Quantity:"
1525 AssociatedControlID="txtProductQuantity"
1526 Runat="server" />
1527 <br />
1528 <asp:TextBox
1529 id="txtProductQuantity"
1530 Columns="5"
1531 Runat="server" />
1532 <asp:RequiredFieldValidator
1533 id="reqProductQuantity"
1534 ControlToValidate="txtProductQuantity"
1535 Text="(Required)"
1536 Display="Dynamic"
1537 Runat="server" />
1538 <asp:CompareValidator
1539 id="CompareValidator1"
1540 ControlToValidate="txtProductQuantity"
1541 Text="(Invalid Quantity)"
1542 Operator="DataTypeCheck"
1543 Type="Integer"
1544 Runat="server" />
1545
1546 <br /><br />
1547
1548 <asp:Button
1549 id="btnSubmit"
1550 Text="Submit Product Order"
1551 OnClick="btnSubmit_Click"
1552 Runat="server" />
1553
1554 </fieldset>
1555
1556 <asp:Label
1557 id="lblResult"
1558 Runat="server" />
1559 <br />
1560 <asp:Label ID="lb2Result" runat="server"></asp:Label>
1561 <br />
1562 <asp:Label ID="lb3Result" runat="server"></asp:Label>
1563
1564 </div>
1565 </form>
1566</body>
1567</html>
1568
1569ValidationForm\ValidForm.aspx.cs
1570using System;
1571using System.Collections.Generic;
1572using System.Linq;
1573using System.Web;
1574using System.Web.UI;
1575using System.Web.UI.WebControls;
1576
1577namespace validationForm.ValidationForm
1578{
1579 public partial class ValidForm : System.Web.UI.Page
1580 {
1581 protected void Page_Load(object sender, EventArgs e)
1582 {
1583
1584 }
1585
1586 protected void btnSubmit_Click(object sender, EventArgs e)
1587 {
1588 if(Page.IsValid)
1589 {
1590 lblResult.Text = "<br />Product: " + txtProductName.Text;
1591 lb2Result.Text = "<br />Price: " + txtProductPrice.Text;
1592 lb3Result.Text = "<br />Quantity: " + txtProductQuantity.Text;
1593 }
1594 }
1595 }
1596}
1597
1598
1599
1600
1601
1602Output:
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614Create Web Form to demonstrate use of Adrotator Control.
1615Code:
1616Addrotator.aspx
1617<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Addrotator.aspx.cs" Inherits="Addrotator.Addrotator.WebForm1" %>
1618
1619<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1620
1621<html xmlns="http://www.w3.org/1999/xhtml">
1622<head runat="server">
1623 <title></title>
1624</head>
1625<body>
1626 <form id="form1" runat="server">
1627
1628 <asp:AdRotator ID="AdRotator1" runat="server" DataSourceID="XmlDataSource3" />
1629 <asp:XmlDataSource ID="XmlDataSource3" runat="server"
1630 DataFile="~/Addrotator/adds.xml"></asp:XmlDataSource>
1631 <asp:XmlDataSource ID="XmlDataSource2" runat="server"
1632 DataFile="~/Addrotator/adds.xml"></asp:XmlDataSource>
1633 <asp:XmlDataSource ID="XmlDataSource1" runat="server"
1634 DataFile="~/Addrotator/adds.xml"></asp:XmlDataSource>
1635
1636 </form>
1637</body>
1638</html>
1639
1640Add.xml
1641<?xml version="1.0" encoding="utf-8" ?>
1642<Advertisements>
1643 <Ad>
1644 <ImageUrl>Chrysanthemum.jpg</ImageUrl>
1645 <NavigateUrl>http://www.1800flowers.com</NavigateUrl>
1646 <AlternateText>
1647 Order flowers, roses, gifts and more
1648 </AlternateText>
1649 <Impressions>20</Impressions>
1650 <Keyword>flowers</Keyword>
1651 </Ad>
1652 <Ad>
1653 <ImageUrl>Jellyfish.jpg</ImageUrl>
1654 <NavigateUrl>http://www.babybouquets.com.au</NavigateUrl>
1655 <AlternateText>Order roses and flowers</AlternateText>
1656 <Impressions>20</Impressions>
1657 <Keyword>gifts</Keyword>
1658 </Ad>
1659 <Ad>
1660 <ImageUrl>Tulips.jpg</ImageUrl>
1661 <NavigateUrl>http://www.flowers2moscow.com</NavigateUrl>
1662 <AlternateText>Send flowers to Russia</AlternateText>
1663 <Impressions>20</Impressions>
1664 <Keyword>russia</Keyword>
1665 </Ad>
1666</Advertisements>
1667
1668Output:
1669
1670
1671
1672
1673
1674Create Web Form to demonstrate use User Controls.
1675Code:
1676WebForm.aspx
1677<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="UserControl.UserControl.WebForm1" %>
1678<%@ Register Src="~/UserControl/MyUserControl.ascx" TagPrefix="uc" TagName="Student"%>
1679
1680<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1681<html xmlns="http://www.w3.org/1999/xhtml">
1682<head runat="server">
1683 <title></title>
1684</head>
1685<body>
1686 <form id="form1" runat="server">
1687 <uc:Student ID="studentcontrol" runat="server" />
1688 </form>
1689</body>
1690</html>
1691
1692MyUserControl.ascx
1693<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUserControl.ascx.cs" Inherits="UserControl.UserControl.MyUserControl" %>
1694<h3>This is User Contro1 </h3>
1695<table>
1696<tr>
1697<td>Name</td>
1698<td>
1699<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
1700</td>
1701</tr>
1702<tr>
1703<td>City</td>
1704<td><asp:TextBox ID="txtcity" runat="server"></asp:TextBox></td>
1705</tr>
1706<tr>
1707<td></td>
1708<td>
1709</td>
1710</tr>
1711<tr>
1712<td></td>
1713<td>
1714<asp:Button ID="txtSave" runat="server" Text="Save" onclick="txtSave_Click" /> </td>
1715</tr>
1716</table><br />
1717<asp:Label ID="Label1" runat="server" ForeColor="Black" Text=" "></asp:Label>
1718
1719MyUserControl.ascx.cs
1720
1721using System;
1722using System.Collections.Generic;
1723using System.Linq;
1724using System.Web;
1725using System.Web.UI;
1726using System.Web.UI.WebControls;
1727
1728namespace UserControl.UserControl
1729{
1730 public partial class MyUserControl : System.Web.UI.UserControl
1731 {
1732 protected void txtSave_Click(object sender, EventArgs e)
1733 {
1734 Label1.Text = "Your Name is " + txtName.Text + " and you are from " + txtcity.Text;
1735 }
1736 }
1737}
1738
1739Output:
1740
1741Practical No.5
1742Create Web Form to demonstrate use of Website Navigation controls and Site Map.
1743Code:
1744Web.sitemap
1745<?xml version="1.0" encoding="utf-8" ?>
1746<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
1747 <siteMapNode url="Default.aspx" title="myhomepage" description="">
1748 <siteMapNode url="myweb1.aspx" title="myfirstpage" description="" />
1749 <siteMapNode url="myweb2.aspx" title="mysecondpage" description="" />
1750 </siteMapNode>
1751</siteMap>
1752
1753Default.aspx
1754<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Practical5a.Default" %>
1755
1756<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1757
1758<html xmlns="http://www.w3.org/1999/xhtml">
1759<head runat="server">
1760 <title></title>
1761</head>
1762<body>
1763 <form id="form1" runat="server">
1764 <div>
1765 <asp:Label ID="Label1" runat="server"
1766 Text="I have designed my website by using SiteMapPath control in ASP.NET"
1767 Font-Bold="True" Font-Names="Arial Black" Font-Size="Large"></asp:Label>
1768 <br />
1769 <br />
1770
1771 <asp:Label ID="Label2" runat="server" Text="sitemap:"></asp:Label>
1772
1773 <asp:SiteMapPath ID="SiteMapPath1" runat="server">
1774 </asp:SiteMapPath>
1775 <br />
1776 <br />
1777 <br />
1778
1779 <asp:Label ID="Label3" runat="server"
1780 Text="Click any link below to go to desired page............."></asp:Label>
1781 <br />
1782 <br />
1783
1784 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/myweb1.aspx">Click here to go to first page </asp:HyperLink>
1785
1786 <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/myweb2.aspx">click here to go to second page</asp:HyperLink>
1787
1788 </div>
1789 </form>
1790</body>
1791</html>
1792
1793myweb1.aspx
1794<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="myweb1.aspx.cs" Inherits="Practical5a.myweb1" %>
1795
1796<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1797
1798<html xmlns="http://www.w3.org/1999/xhtml">
1799<head runat="server">
1800 <title></title>
1801</head>
1802<body>
1803 <form id="form1" runat="server">
1804 <div>
1805
1806 <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial Black"
1807 Font-Size="Large"
1808 Text="Thank you for clicking.This is My First Webpage.............."></asp:Label>
1809 <br />
1810 <br />
1811
1812
1813 <asp:Label ID="Label2" runat="server" Text="SiteMap:"></asp:Label>
1814
1815 <asp:SiteMapPath ID="SiteMapPath1" runat="server">
1816 </asp:SiteMapPath>
1817 <br />
1818 <br />
1819
1820 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/myweb2.aspx">click here to go to mywebpage2</asp:HyperLink>
1821 </div>
1822 </form>
1823</body>
1824</html>
1825
1826myweb.aspx
1827<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="myweb2.aspx.cs" Inherits="Practical5a.myweb2" %>
1828
1829<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1830
1831<html xmlns="http://www.w3.org/1999/xhtml">
1832<head runat="server">
1833 <title></title>
1834</head>
1835<body>
1836 <form id="form1" runat="server">
1837 <div>
1838 <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial Black"
1839 Font-Size="Large"
1840 Text="Thanx for Clicking.This is my Second webpage by using SiteMapPath control.................">
1841 </asp:Label>
1842 </div>
1843 <p>
1844
1845 <asp:Label ID="Label2" runat="server" Text="SiteMap: "></asp:Label>
1846
1847 <asp:SiteMapPath ID="SiteMapPath1" runat="server">
1848 </asp:SiteMapPath>
1849 </p>
1850 <p> </p>
1851 <p>
1852
1853
1854 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Click here to go to Home page</asp:HyperLink>
1855 </p>
1856 </form>
1857</body>
1858</html>
1859
1860
1861Output:
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883Create a web application to demonstrate use of Master Page with applying Styles and Themes for page beautification.
1884Create a web application to demonstrate various states of ASP.NET Pages.
1885
1886Code:
1887
1888Default.aspx
1889
1890<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="State.Default" %>
1891
1892<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1893
1894<html xmlns="http://www.w3.org/1999/xhtml">
1895<head runat="server">
1896 <title></title>
1897</head>
1898<body>
1899 <form id="form1" runat="server">
1900 <div>
1901
1902 </div>
1903 </form>
1904</body>
1905</html>
1906
1907Default.aspx.cs
1908
1909using System;
1910using System.Collections.Generic;
1911using System.Linq;
1912using System.Web;
1913using System.Web.UI;
1914using System.Web.UI.WebControls;
1915
1916namespace State
1917{
1918 public partial class Default : System.Web.UI.Page
1919 {
1920 protected void Page_Load(object sender, EventArgs e)
1921 {
1922 Response.Write("The num of users online=" + Application["user"].ToString());
1923 }
1924 }
1925}
1926
1927
1928
1929
1930Global.asax.cs
1931
1932using System;
1933using System.Collections.Generic;
1934using System.Linq;
1935using System.Web;
1936using System.Web.Security;
1937using System.Web.SessionState;
1938
1939namespace State
1940{
1941 public class Global : System.Web.HttpApplication
1942 {
1943
1944 protected void Application_Start(object sender, EventArgs e)
1945 {
1946 //this event is execute only once when application start and it stores the
1947 server memory until the worker process is restart
1948 Application["user"] = 0;
1949 }
1950
1951 protected void Session_Start(object sender, EventArgs e)
1952 {
1953 //when session in start application variable is increased by 1
1954 Application.Lock();
1955 Application["user"] = (int)Application["user"] + 1;
1956 Application.UnLock();
1957 }
1958
1959 protected void Application_BeginRequest(object sender, EventArgs e)
1960 {
1961
1962 }
1963
1964 protected void Application_AuthenticateRequest(object sender, EventArgs e)
1965 {
1966
1967 }
1968
1969 protected void Application_Error(object sender, EventArgs e)
1970 {
1971
1972 }
1973
1974 protected void Session_End(object sender, EventArgs e)
1975 {
1976 //when session in end application variable is decrease by 1
1977 Application.Lock();
1978 Application["user"] = (int)Application["user"] - 1;
1979 Application.UnLock();
1980 }
1981
1982 protected void Application_End(object sender, EventArgs e)
1983 {
1984
1985 }
1986 }
1987}
1988
1989Web.config
1990
1991<?xml version="1.0"?>
1992
1993<!--
1994 For more information on how to configure your ASP.NET application, please visit
1995 http://go.microsoft.com/fwlink/?LinkId=169433
1996 -->
1997
1998<configuration>
1999 <system.web>
2000 <compilation debug="true" targetFramework="4.0" />
2001 <sessionState mode="InProc" timeout="20" cookieless="true"></sessionState>
2002 </system.web>
2003</configuration>
2004
2005Output:
2006
2007
2008
2009
2010Practical No.6
2011Create a web application bind data in a multiline textbox by querying in another textbox.
2012Code:
2013DatabaseForm.aspx
2014<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DatabaseForm.aspx.cs" Inherits="Practical6a.NewFolder1.DatabaseForm" %>
2015
2016<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2017
2018<html xmlns="http://www.w3.org/1999/xhtml">
2019<head runat="server">
2020 <title>Customer Data</title>
2021 </head>
2022<body>
2023 <form id="form1" runat="server">
2024 <div>
2025
2026 Enter The Query To View Data:
2027 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
2028 <br />
2029 <br />
2030 <br />
2031 Data Stored in Database:
2032 <br />
2033 <br />
2034 <br />
2035
2036 <asp:ListBox ID="ListBox1" runat="server" Height="133px" Width="149px"></asp:ListBox>
2037 <br />
2038 <br />
2039 <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click"/>
2040
2041 </div>
2042 </form>
2043</body>
2044</html>
2045
2046DatabaseForm.aspx.cs
2047using System;
2048using System.Collections.Generic;
2049using System.Linq;
2050using System.Web;
2051using System.Web.UI;
2052using System.Web.UI.WebControls;
2053using System.Data;
2054using System.Data.SqlClient;
2055using System.Configuration;
2056
2057namespace Practical6a.NewFolder1
2058{
2059 public partial class DatabaseForm : System.Web.UI.Page
2060 {
2061 SqlConnection cn = new SqlConnection("Data Source=MAverickCD-PC\\sqlexpress;Initial Catalog=Student;Integrated Security=True;Pooling=False");
2062 SqlCommand cmd = new SqlCommand();
2063 SqlDataReader ds;
2064 protected void Page_Load(object sender, EventArgs e)
2065 {
2066 cn.Open();
2067 cmd.Connection=cn;
2068 }
2069 protected void Button1_Click(object sender, EventArgs e)
2070 {
2071 cmd.CommandText = "select * from customer";
2072 ds = cmd.ExecuteReader();
2073 while (ds.Read())
2074 {
2075 ListBox1.Items.Add(ds[0].ToString() +"\t" + ds[1].ToString());
2076 }
2077 }
2078 }
2079}
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090Output:
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106Create a web application to display records by using database.
2107
2108
2109
2110protected void Button1_Click(object sender, EventArgs e)
2111{
2112string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2113SqlConnection con = new SqlConnection(connStr);
2114SqlCommand cmd = new SqlCommand("Select City, State from Customer", con);
2115con.Open();
2116SqlDataReader reader = cmd.ExecuteReader();
2117while (reader.Read())
2118{
2119Label1.Text += reader["City"].ToString() + " " + reader["State"].ToString() + "<br>";
2120}
2121reader.Close();
2122con.Close();
2123}
2124
2125Output:
2126
2127
2128
2129
2130
2131Demonstrate the use of Datalist link control.
2132
21331. Drag the Datalist control to our web page form toolbox->Data-> Datalist.
21342. Then select Choose Data Source Option and select <New Data Source>.
2135
2136
21373. Now Select SQL Database from options and Click Ok button.
2138
2139
21404. In next window click on New Connection button.
21415. In add connection window Select the available SQL Server Name
21426. Keep the Authentication as Windows Authentication.
21437. After that select Attach a Database file radio button. Here we have to select the database that we have created in our application. (Usually it will be in Documents folder under Visual Studio 2015/ Websites).
21448. After selection of Database file. We can also Test the connection.
21459. Then Click on OK button.
2146
214710. Once the Connection is made then click on Next button from Data Source Wizard.
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163Practical No.7
2164Create a web application to display Databinding using Dropdownlist control.
2165
2166using System;
2167using System.Collections.Generic;
2168using System.Linq;
2169using System.Web;
2170using System.Web.UI;
2171using System.Web.UI.WebControls;
2172using System.Data;
2173using System.Data.SqlClient;
2174using System.Configuration;
2175public partial class DBDropDown : System.Web.UI.Page
2176{
2177 protected void Page_Load(object sender, EventArgs e)
2178 {
2179 if (IsPostBack == false)
2180 {
2181 string connStr =
2182ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2183 SqlConnection con = new SqlConnection(connStr);
2184 SqlCommand cmd = new SqlCommand("Select Distinct City from Customer", con);
2185 con.Open();
2186 SqlDataReader reader = cmd.ExecuteReader();
2187 DropDownList1.DataSource = reader;
2188 DropDownList1.DataTextField = "City";
2189 DropDownList1.DataBind();
2190 reader.Close();
2191 con.Close();
2192 }
2193 }
2194 protected void Button1_Click(object sender, EventArgs e)
2195 {
2196 Label1.Text = "The You Have Selected : " + DropDownList1.SelectedValue;
2197 }
2198}
2199
2200
2201
2202
2203
2204
2205
2206Output:
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231Create a web application for to display the Postal Code no of Customer using database.
2232
2233Code:
2234
2235using System;
2236using System.Collections.Generic;
2237using System.Linq;
2238using System.Web;
2239using System.Web.UI;
2240using System.Web.UI.WebControls;
2241using System.Data;
2242using System.Data.SqlClient;
2243using System.Configuration;
2244public partial class PostalCodeByCity : System.Web.UI.Page
2245{
2246
2247 protected void Button1_Click(object sender, EventArgs e)
2248 {
2249 Label1.Text = ListBox1.SelectedValue;
2250 }
2251 protected void Page_Load(object sender, EventArgs e)
2252 {
2253 if (IsPostBack == false)
2254 {
2255 string connStr =
2256ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2257 SqlConnection con = new SqlConnection(connStr);
2258 SqlCommand cmd = new SqlCommand("Select Distinct POSTAL_CODE from Customer",
2259con);
2260 con.Open();
2261SqlDataReader reader = cmd.ExecuteReader();
2262 ListBox1.DataSource = reader;
2263 ListBox1.DataTextField = "City";
2264 ListBox1.DataValueField = "POSTAL_CODE";
2265 ListBox1.DataBind();
2266
2267 reader.Close();
2268 con.Close();
2269 }
2270 }
2271}
2272
2273
2274Output:
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301Create a web application for inserting and deleting record from a database. (Using Execute-Non Query).
2302
2303Code:
2304using System;
2305using System.Collections.Generic;
2306using System.Linq;
2307using System.Web;
2308using System.Web.UI;
2309using System.Web.UI.WebControls;
2310using System.Data;
2311using System.Data.SqlClient;
2312using System.Configuration;
2313public partial class ExecuteNonQuery : System.Web.UI.Page
2314{
2315 protected void Button1_Click(object sender, EventArgs e)
2316 {
2317 string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2318 SqlConnection con = new SqlConnection(connStr);
2319 string InsertQuery = "insert into BRANCH values(@ADDRESS, @CITY, @NAME, @STATE,
2320@ZIP_CODE)";
2321 SqlCommand cmd = new SqlCommand(InsertQuery, con);
2322 cmd.Parameters.AddWithValue("@ADDRESS", TextBox1.Text);
2323 cmd.Parameters.AddWithValue("@CITY", TextBox2.Text);
2324 cmd.Parameters.AddWithValue("@NAME", TextBox3.Text);
2325 cmd.Parameters.AddWithValue("@STATE", TextBox4.Text);
2326 cmd.Parameters.AddWithValue("@ZIP_CODE", TextBox5.Text);
2327 con.Open();
2328 cmd.ExecuteNonQuery();
2329 Label1.Text = "Record Inserted Successfuly.";
2330 con.Close();
2331 }
2332 protected void Button2_Click(object sender, EventArgs e)
2333 {
2334 string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2335 SqlConnection con = new SqlConnection(connStr);
2336 string InsertQuery = "delete from branch where NAME=@NAME";
2337 SqlCommand cmd = new SqlCommand(InsertQuery, con);
2338 cmd.Parameters.AddWithValue("@NAME", TextBox1.Text);
2339 con.Open( );
2340 cmd.ExecuteNonQuery( );
2341 Label1.Text = "Record Deleted Successfuly.";
2342 con.Close( );
2343 }
2344}
2345using System.Linq;
2346using System.Web;
2347using System.Web.UI;
2348using System.Web.UI.WebControls;
2349using System.Data;
2350using System.Data.SqlClient;
2351using System.Configuration;
2352public partial class ExecuteNonQuery : System.Web.UI.Page
2353{
2354 protected void Button1_Click(object sender, EventArgs e)
2355 {
2356 string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2357 SqlConnection con = new SqlConnection(connStr);
2358 string InsertQuery = "insert into BRANCH values(@ADDRESS, @CITY, @NAME, @STATE,
2359@ZIP_CODE)";
2360 SqlCommand cmd = new SqlCommand(InsertQuery, con);
2361 cmd.Parameters.AddWithValue("@ADDRESS", TextBox1.Text);
2362 cmd.Parameters.AddWithValue("@CITY", TextBox2.Text);
2363 cmd.Parameters.AddWithValue("@NAME", TextBox3.Text);
2364 cmd.Parameters.AddWithValue("@STATE", TextBox4.Text);
2365 cmd.Parameters.AddWithValue("@ZIP_CODE", TextBox5.Text);
2366 con.Open();
2367 cmd.ExecuteNonQuery();
2368 Label1.Text = "Record Inserted Successfuly.";
2369 con.Close();
2370 }
2371 protected void Button2_Click(object sender, EventArgs e)
2372 {
2373 string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
2374 SqlConnection con = new SqlConnection(connStr);
2375 string InsertQuery = "delete from branch where NAME=@NAME";
2376 SqlCommand cmd = new SqlCommand(InsertQuery, con);
2377 cmd.Parameters.AddWithValue("@NAME", TextBox1.Text);
2378 con.Open( );
2379 cmd.ExecuteNonQuery( );
2380 Label1.Text = "Record Deleted Successfuly.";
2381 con.Close( );
2382 }
2383}
2384
2385Output:
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401Practical No.8
2402Create a web application to demonstrate various uses and properties of SqlDataSource.
2403Code:
2404WebForm.aspx.cs
2405using System;
2406using System.Collections.Generic;
2407using System.Linq;
2408using System.Web;
2409using System.Web.UI;
2410using System.Web.UI.WebControls;
2411using System.Data;
2412using System.Data.SqlClient;
2413using System.Configuration;
2414
2415
2416namespace Practical8a
2417{
2418 public partial class WebForm : System.Web.UI.Page
2419 {
2420 SqlConnection cn = new SqlConnection("Data Source=MAverickCD-PC\\sqlexpress;Initial Catalog=Student;Integrated Security=True;Pooling=False");
2421 SqlCommand cmd = new SqlCommand();
2422 SqlDataReader ds;
2423 SqlDataSource s = new SqlDataSource();
2424 protected void Page_Load(object sender, EventArgs e)
2425 {
2426 cn.Open();
2427 s.ConnectionString = "Data Source=MAverickCD-PC\\sqlexpress;Initial Catalog=Student;Integrated Security=True;Pooling=False";
2428 }
2429
2430 protected void Button1_Click(object sender, EventArgs e)
2431 {
2432 s.SelectCommand = "select * from Booklet";
2433 GridView1.DataSource = s;
2434 GridView1.DataBind();
2435 }
2436
2437 protected void Button2_Click(object sender, EventArgs e)
2438 {
2439 SqlParameter p1 =new SqlParameter(), p2 = new SqlParameter(), p3 = new SqlParameter(), p4 = new SqlParameter();
2440 s.InsertParameters.Add("p1", System.Data.DbType.Int16, TextBox1.Text);
2441 s.InsertParameters.Add("p2", System.Data.DbType.String, TextBox2.Text);
2442 s.InsertParameters.Add("p3", System.Data.DbType.String, TextBox3.Text);
2443 s.InsertParameters.Add("p4", System.Data.DbType.String, TextBox4.Text);
2444 s.InsertCommand = "insert into Booklet Values(@p1,@p2,@p3,@p4)";
2445 s.Insert();
2446 }
2447
2448 protected void Button3_Click(object sender, EventArgs e)
2449 {
2450 SqlParameter p1 = new SqlParameter(), p2 = new SqlParameter();
2451 s.UpdateParameters.Add("p1", System.Data.DbType.Int16, TextBox1.Text);
2452 s.UpdateParameters.Add("p2", System.Data.DbType.String, TextBox2.Text);
2453 s.UpdateCommand = "update Booklet SET AUTHOR=@p2 where SRNO=@p1";
2454 s.Update();
2455 }
2456
2457 protected void Button4_Click(object sender, EventArgs e)
2458 {
2459 SqlParameter p1 = new SqlParameter();
2460 s.DeleteParameters.Add("p1", System.Data.DbType.Int16, TextBox1.Text);
2461 s.DeleteCommand = "delete Booklet where SRNO=@p1";
2462 s.Delete();
2463 }
2464
2465 }
2466}
2467
2468
2469
2470
2471
2472
2473
2474Output:
2475
2476Insert and View:
2477
2478
2479
2480Modify and View:
2481
2482Delete and View:
2483
2484
2485Create a web application to demonstrate data binding using Details View and Form View Control.
2486
2487Code:
2488<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataSourceID= "SqlDataSource1">
2489<EditItemTemplate>
2490sno:
2491<asp:TextBox ID="snoTextBox" runat="server" Text='<%#Bind("sno")%>'/>
2492<br/>
2493name:
2494<asp:TextBox ID="nameTextBox" runat="server" Text='<%#Bind("name")%>'/>
2495<br/>
2496class:
2497<asp:TextBox ID="classTextBox" runat="server" Text='<%#Bind("class")%>'/>
2498<br/>
2499<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"/>
2500&nsbp; <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"/>
2501</EditItemTemplate>
2502<HeaderTemplate>
2503Students List
2504</HeaderTemplate>
2505<InsertItemTemplate>
2506sno:
2507<asp:TextBox ID="snoTextBox" runat="server" Text='<%#Bind("sno")%>'/>
2508<br/>
2509name:
2510<asp:TextBox ID="nameTextBox" runat="server" Text='<%#Bind("name")%>'/>
2511<br/>
2512class:
2513<asp:TextBox ID="classTextBox" runat="server" Text='<%#Bind("class")%>'/>
2514<br/>
2515<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"/>
2516&nsbp; <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"/>
2517</InsertItemTemplate>
2518<ItemTemplate>
2519sno:
2520<asp:Label ID="snoLabel" runat="server" Text='<%#Bind("sno")%>'/>
2521<br/>
2522name:
2523<asp:Label ID="nameLabel" runat="server" Text='<%#Bind("name")%>'/>
2524<br/>
2525class:
2526<asp:Label ID="classLabel" runat="server" Text='<%#Bind("class")%>'/>
2527<br/>
2528</ItemTemplate>
2529</asp:FormView>
2530Output:
2531
2532
2533
2534Create a web application to display Using Disconnected Data Access and DataBinding using GridView.
2535
2536CODE:
2537using System;
2538using System.Collections.Generic;
2539using System.Linq;
2540using System.Web;
2541using System.Web.UI;
2542using System.Web.UI.WebControls;
2543using System.Data.SqlClient;
2544using System.Data;
2545public partial class_Default:System.Web.UI.Page
2546{
2547SqlConnection cn;
2548SqlCommand co;
2549SqlDataAdapter ds;
2550DataSet da;
2551protected void Page_Load(object sender,EventArgs e)
2552{
2553cn=new SqlConnection("DataSource=ADMINMURALI-PC\\SQLEXPRESS; Initial Catalog=students; Integrated Security=True")
2554co=new SqlCommand ();
2555ds=new SqlDataAdapter ();
2556da=new DataSet ();
2557}
2558protected void Button_Click(object sender,EventArgs e)
2559{
2560co.CommandText="select*from stdetail";
2561co.Connection=cn;
2562ds.SelectCommand=co;
2563ds.Fill(da,"stdetail");
2564GridView1.DataSource=da.Tables[0];
2565GridView1.DataBind();
2566}
2567
2568
2569
2570
2571
2572
2573Practical No.9
2574Create a web application to demonstrate use of Grid View control template and Grid View Hyperlink.
2575Code:
2576WebForm.aspx
2577<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm.aspx.cs" Inherits="Practical9a.WebForm" %>
2578
2579<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2580
2581<html xmlns="http://www.w3.org/1999/xhtml">
2582<head runat="server">
2583 <title></title>
2584</head>
2585<body>
2586 <form id="form1" runat="server">
2587 <div>
2588
2589 <asp:GridView ID="GridView1" runat="server" AllowSorting="True"
2590 AutoGenerateColumns="False" DataKeyNames="SRNO" DataSourceID="SqlDataSource1">
2591 <Columns>
2592 <asp:CommandField ShowSelectButton="True" />
2593 <asp:BoundField DataField="SRNO" HeaderText="SRNO" ReadOnly="True"
2594 SortExpression="SRNO" />
2595 <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
2596 <asp:BoundField DataField="CLASS" HeaderText="CLASS" SortExpression="CLASS" />
2597 <asp:BoundField DataField="CITY" HeaderText="CITY" SortExpression="CITY" />
2598 </Columns>
2599 </asp:GridView>
2600 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
2601 ConnectionString="<%$ ConnectionStrings:StudentConnectionString %>"
2602 SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
2603
2604 </div>
2605 </form>
2606</body>
2607</html>
2608
2609
2610
2611Webform.aspx.cs
2612using System;
2613using.System.Collections.Generic;
2614using.System.Linq;
2615using.system.Web;
2616using.System.Web.UI;
2617using.System.Web.UI.WebControls;
2618public partial class_Default : System.Web.UI.Page
2619{
2620protected void Page Load(object sender, EventArgs e)
2621{
2622}
2623protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
2624{
2625//Response. Write(GridView1.SelectedValue.ToString());
2626//Response.RedirectDefault2.aapxeat+ GridView1.SelectedValue ToString())
2627}
2628Protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
2629{
2630Var h=(HyperLink)e.Row.FindControl("hyperlink");
2631If(h!=null)
2632{
2633h.navigateUrl= "default2.aspx"+"class?="+h.Text;
2634}
2635}
2636}
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648Output:
2649
2650WebForm2.aspx.cs
2651using system;
2652usingSystem.Collections.Generic;
2653using System. Linq;
2654usingSystem.Web;
2655usingSystem.Web.UI;
2656usingSystem.Web.UI.WebControls;
2657public partial class Default2 : System.Web.UI.Page
2658{
2659SqlDataSource s = new SqlDataSource();
2660protected void Page_Load(object sender,EventArgs e)
2661{
2662s.ConnectionString=â€Data Source=ADMINMURALI-PC\\sqlexpress;Initial
2663Catlog=student;Integrated Security=Trueâ€;
2664s.SelectCommand = “select * from stdetail where class = “+Request.QueryString[“class’]+â€â€;
2665GridView1.DataSource = s;
2666GridView1.DataBind();
2667 }
2668}
2669
2670
2671
2672Output:
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689Create a web application to demonstrate use of Grid View button column and Grid View events.
2690Code:
2691WebForm.aspx
2692<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm.aspx.cs" Inherits="Practical9b.WebForm" %>
2693
2694<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2695
2696<html xmlns="http://www.w3.org/1999/xhtml">
2697<head runat="server">
2698 <title></title>
2699</head>
2700<body>
2701 <form id="form1" runat="server">
2702 <div>
2703
2704 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
2705 BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
2706 CellPadding="3" DataKeyNames="SRNO" DataSourceID="SqlDataSource1"
2707 ForeColor="Black" GridLines="Vertical">
2708 <AlternatingRowStyle BackColor="#CCCCCC" />
2709 <Columns>
2710 <asp:BoundField DataField="SRNO" HeaderText="SRNO" ReadOnly="True"
2711 SortExpression="SRNO" />
2712 <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" />
2713 <asp:BoundField DataField="CLASS" HeaderText="CLASS" SortExpression="CLASS" />
2714 <asp:BoundField DataField="CITY" HeaderText="CITY" SortExpression="CITY" />
2715 </Columns>
2716 <FooterStyle BackColor="#CCCCCC" />
2717 <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
2718 <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
2719 <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
2720 <SortedAscendingCellStyle BackColor="#F1F1F1" />
2721 <SortedAscendingHeaderStyle BackColor="#808080" />
2722 <SortedDescendingCellStyle BackColor="#CAC9C9" />
2723 <SortedDescendingHeaderStyle BackColor="#383838" />
2724 </asp:GridView>
2725 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
2726 ConnectionString="<%$ ConnectionStrings:StudentConnectionString %>"
2727 SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
2728
2729 </div>
2730 </form>
2731</body>
2732</html>
2733
2734WebForm.aspx.cs
2735
2736using System;
2737using.System.Collections.Generic;
2738usingSystem.Linq;
2739usingSystem.Web;
2740usingSystem.Web.UI;
2741usingSystem.Web.UI.WebControls;
2742usingSystem.Drawing;
2743public partial class_Default : System.Web.UI.Page
2744{
2745 Protected void Page_Load(object sender,EventArgs e)
2746{
2747}
2748Protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
2749{
2750}
2751Protected void GridView1_RowCommand(object sender,GridviewCommandEventArgs e)
2752{
2753If (e.CommandName==â€b1â€)
2754{
2755Response.Write(e.CommandName);
2756// GridView1.SelectedRowStyle.BackColor=System.Drawing.Color.Brown;
2757GridView1.Rows[Convert.ToInt16(e.CommandArgument)].BackColor= System.Drawing.Color.Blue;
2758 }
2759 }
2760}
2761
2762
2763
2764
2765
2766
2767
2768Output:
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784Create a web Application demonstrate Grid View paging and Creating own table format using Grid View.
2785Code:
2786WebForm.aspx
2787<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm.aspx.cs" Inherits="Practical9c.WebForm" %>
2788
2789<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2790
2791<html xmlns="http://www.w3.org/1999/xhtml">
2792<head runat="server">
2793 <title>Grid View</title>
2794</head>
2795<body>
2796 <form id="form1" runat="server">
2797 <div>
2798
2799 <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
2800 AutoGenerateColumns="False" DataKeyNames="SRNO" DataSourceID="SqlDataSource1">
2801 <Columns>
2802 <asp:BoundField DataField="SRNO" HeaderText="SRNO" ReadOnly="True"
2803 SortExpression="SRNO" />
2804 <asp:BoundField DataField="AUTHOR" HeaderText="AUTHOR"
2805 SortExpression="AUTHOR" />
2806 <asp:BoundField DataField="PHONENO" HeaderText="PHONENO"
2807 SortExpression="PHONENO" />
2808 <asp:BoundField DataField="BOOKNAME" HeaderText="BOOKNAME"
2809 SortExpression="BOOKNAME" />
2810 </Columns>
2811 </asp:GridView>
2812 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
2813 ConnectionString="<%$ ConnectionStrings:StudentConnectionString %>"
2814 SelectCommand="SELECT * FROM [Booklet]"></asp:SqlDataSource>
2815 <br />
2816 <asp:DropDownList ID="DropDownList1" runat="server"
2817 DataSourceID="SqlDataSource1" DataTextField="SRNO" DataValueField="SRNO">
2818 </asp:DropDownList>
2819
2820 </div>
2821 </form>
2822</body>
2823</html>
2824
2825
2826WebForm.aspx.cs
2827using System;
2828using.System.Collections.Generic;
2829usingSystem.Linq;
2830usingSystem.Web;
2831usingSystem.Web.UI;
2832usingSystem.Web.UI.WebControls;
2833usingSystem.Drawing;
2834public partial class_Default : System.Web.UI.Page
2835{
2836 Protected void Page_Load(object sender,EventArgs e)
2837{
2838}
2839Protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
2840{
2841GridView1.PageIndex = e.NewPageIndex;
2842
2843}
2844Protected void GridView1_RowCommand(object sender,GridviewCommandEventArgs e)
2845{
2846}
2847Protected void DropDownList1_SelectedIndexChanged(object sender,EventArgs e)
2848{
2849GridView1.PageIndex = DropDownList1.SelectedIndex;
2850}
2851}
2852
2853Output:
2854
2855
2856Output:
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872Practical No.10
2873Create a web application to demonstrate reading and writing operation with xml.
2874Code:
2875 WebForm.aspx
2876<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm.aspx.cs" Inherits="Practical10a.WebForm" %>
2877
2878<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2879
2880<html xmlns="http://www.w3.org/1999/xhtml">
2881<head runat="server">
2882 <title></title>
2883</head>
2884<body>
2885 <form id="form1" runat="server">
2886 <div>
2887
2888 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Read XML" />
2889 <br />
2890 <br />
2891 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
2892 <br />
2893 <br />
2894 <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Write XML" />
2895
2896 </div>
2897 </form>
2898</body>
2899</html>
2900
2901WebForm.aspx.cs
2902using System;
2903using System.Collections.Generic;
2904using System.Linq;
2905using System.Web;
2906using System.Web.UI;
2907using System.Web.UI.WebControls;
2908using System.Xml;
2909
2910namespace Practical10a
2911{
2912 public partial class WebForm : System.Web.UI.Page
2913 {
2914 protected void Page_Load(object sender, EventArgs e)
2915 {
2916
2917 }
2918
2919 protected void Button1_Click(object sender, EventArgs e)
2920 {
2921 XmlReader red = XmlReader.Create(@"c:\users\maverickcd\documents\visual studio 2010\Projects\Practical10a\Practical10a\XMLFile.xml");
2922 while(red.Read())
2923 {
2924 if(red.NodeType.Equals(XmlNodeType.Element))
2925 {
2926 string s= Label1.Text+" ";
2927 Label1.Text =s + red.Name;
2928 }
2929 }
2930 red.Close() ;
2931 }
2932
2933 protected void Button2_Click(object sender, EventArgs e)
2934 {
2935 XmlWriterSettings set = new XmlWriterSettings();
2936 set.Indent = true;
2937 XmlWriter wr= XmlWriter.Create(@"c:\users\maverickcd\documents\visual studio 2010\Projects\Practical10a\Practical10a\XMLFile2.xml", set);
2938 wr.WriteStartDocument();
2939 wr.WriteComment("example of write to xml document ");
2940 wr.WriteStartElement("student");
2941 wr.WriteEndElement();
2942 }
2943 }
2944}
2945
2946XMLFile.xml
2947Empty file
2948
2949
2950
2951
2952XMLFile2.xml
2953<? xml version ="1.0" encoding="utf-8"? >
2954
2955<student >
2956 <name>xyz</name>
2957 <roll>1</roll>
2958</student >
2959
2960Output:
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970Create a Web application to display time in textbox when user clicks on show time button. Implement 2 second delay in between , and within 2 second delay display message please wait for sometime(using AJAX Control)
2971Code:
2972Webform.aspx
2973<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Practical10c.WebForm1" %>
2974
2975<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2976
2977<html xmlns="http://www.w3.org/1999/xhtml">
2978<head runat="server">
2979 <title></title>
2980</head>
2981<body>
2982 <form id="form1" runat="server">
2983 <div>
2984 <asp:ScriptManager ID="ScriptManager1" runat="server" >
2985 </asp:ScriptManager>
2986 <br/>
2987 <br/>
2988
2989 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
2990
2991 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" style="margin-left: 14px" Text= "SHOW TIME" />
2992 <br/>
2993 <br/>
2994 <asp:UpdateProgress ID ="UpadateProgress1" runat="server" >
2995 <ProgressTemplate >
2996 PLEASE WAIT FOR SOMETIME
2997 </ProgressTemplate >
2998 </asp:UpdateProgress >
2999 </div>
3000 <asp:UpdatePanel ID="UpdatPanel1" runat="server" >
3001 </asp:UpdatePanel>
3002
3003 </form>
3004</body>
3005</html>
3006
3007
3008
3009
3010
3011WebForm.aspx.cs
3012using System;
3013using System.Collections.Generic;
3014using System.Linq;
3015using System.Web;
3016using System.Web.UI;
3017using System.Web.UI.WebControls;
3018
3019namespace Practical10c
3020{
3021 public partial class WebForm1 : System.Web.UI.Page
3022 {
3023 protected void Page_Load(object sender, EventArgs e)
3024 {
3025 System.Threading.Thread.Sleep(2000);
3026 }
3027
3028 protected void Button1_Click(object sender, EventArgs e)
3029 {
3030 TextBox1.Text = DateTime.Now.ToLongTimeString();
3031 }
3032 }
3033}
3034
3035Output: