Download - ASP Net Notes1
-
8/9/2019 ASP Net Notes1
1/173
- 1 -
-
8/9/2019 ASP Net Notes1
2/173
INTRODUCTION
ASP 2.0 using c# or VB.net
Database SQL Server, Xm
!t is use" or $eb "eveo%ment
.Net Architecture
ASP.&et $eb A%%ication B'L (in"o$s A%%ication
'L)
*S
B'L Base cass anguage
'L) 'ommon Language )untime
*S *%erating S+stem
CLR
!t is an environment $ic manages te eecution o co"ing. !t manages-
/emor+ management
arbage coection o su%%ort muti%e anguage
&ote "ierence b3$ 'L) n 4V/ is tat 4V/ on+ su%%ort singe anguage i.e. 5ava6
BCL
'oection o stan"ar" cass or common cass $ic $e can use .net su%%orte" anguage
7.g. - in VB.&et $e use 8integer9 n in c# $e use 8int9 but $e can use 8int1:9, 8int;29 in
bot.
&ote ASP.net it is 5ust a tecnoog+ tat runs on server $it some anguage.
(e must ave common anguage s%eciication or com%ier to run .net.
Why .Net?
Po$eru
)eusabiit+
-
8/9/2019 ASP Net Notes1
3/173
!n $eb "eveo%ment a%%ication run on server. At cient si"e tere is sim%e >tm
%age $ic is un"erstan" b+ a bro$ser
Server in .net case is /icrosotrunning n "eveo%ing environment6
.net is not %atorm in"e%en"ent so $e must ave /icrosot *S on te server an"
an+ting on cient co? cient on+ ave >/L %age
.Net Framework
'onnection o toos, tecnoog+ n anguage $ic $or= togeter to communicate
on muti%e %atorm.
o run .net a%%ication $e must ave .net rame$or=
-
8/9/2019 ASP Net Notes1
4/173
4# ';
/S!L/icrosot !nterme"iate Language m3c in"e%en"ent6
(e must ave 4! 5ust in time6 com%ier at server $ic ma=e native co"e $ic
is m3c "e%en"ent n 'P s%eciic
A$%ata&es o! 'IT(
4itna co"e cai+e utna i com%ie =arte ai
7= baar native co"e banana =e baa" "ubara nai banate
Ty"es o! 'IT(
P)7
7'>&*
&*)/AL
Com"i#atio mo$es i A)*.Net +.,
!n %ace com%iation b+ "eaut6
Singe ie com%ier at run time in $ic canges as been "one.
se" on te sites $ere canges are "one reguar+
*ne "isa"vantage o tis is tat $e nee" source co"e6
Site %re com%iation
!t use com%ier name as 8ASPnetEcom%ier9.
!t ma=es com%ii?ation ie or eac ie starting $it 8a%%E$eb9 an" ater tat
An+ ran"om generate" name i=e abc ----- a%%E$ebi5gt
+? ----- a%%E$ebg"!t as better %erormance
!t is ast
A"v F &o source co"e reGuire"
Disa"vantage F even singe cange reGuire u com%iation o site
Re-uiremets !or A)*.Net
Server
!!S !nternet inormation service6 it is use" $it 1.1 version
!t is not oa"e" on XP-ome e"ition
(e can oa" it troug'ontro %ane --- a"" remove ies--- $in"o$s com%onents
o cange ome "irector+
'ontro %ane --- a"m toos --- !!S --- 'S ---$eb sites--- "eaut $eb site)igt cic=6--- Pro%erties --- ome "irector+
- -
-
8/9/2019 ASP Net Notes1
5/173
B+ "eaut 8cHnet%ubH$$$root96
o cec= $eater server is running or not
'ontro %ane --- a"m toos --- !!S --- 'S ---$eb sites--- "eaut $eb site)igt cic=6---start3sto%. ! start n sto% is $or=ing !!S is running
(eb Server incu"e" in version 2.0
!t can run on XP-ome e"ition
XP %roessiona $it service %ac= 23
200; server $it service %ac= 13
(in 2000 %roessiona service %ac=
Visua stu"io 200
First a""#icatio
P !!S6
Language Visua basic
'#
/tesio
.as% "esigning or %resentation
.as%.v" co"e ie VB6
.as%.cs co"e ie '#6
'once%t o Partia cass is intro"uce" in ver 2.0 $ic means $e can "ivi"e te
cass into number o %arts. Beneit o tis s+stem co"euse" b+ s+stem6 can be
store in one %artia cass n "eveo%er co"e in anoter.
(e can inerit on+ one cass not muti%e ineritance in .net
(e "ierciate meto", names%ace, %ro%ert+, cass b+ tere s+mbo
I J names%ace; boes cass
Pin= bo meto" etc
Bi5ai event
>an" %ro%ert+
&ames%ace is coection o casses it ma+ be neste"
- -
-
8/9/2019 ASP Net Notes1
6/173
A %roce"ures $ic ave an"es in te en" are events.
Page oa" event is ire" irst $itout even caing tis event. !t as to %arameters
1stor reerence an" 2n"or manage event "ata
(in"o$s reGuire"Soution e%orer
oobo
>/L 'ontro bac=groun" com%atibiit+6
)un on cient si"e an" are bro$ser "e%en"ent(eb Server contro
)un on server si"e an" are bro$ser in"e%en"entPro%ert+ $in"o$6
$o t+%es o a+out
ri" a+out avaiabe in ver 1.16
-
8/9/2019 ASP Net Notes1
7/173
o sto% scroing o $in"o$ $en %age is %oste" bac=
'e.Smartaigation = true
o com%ie ine b+ ine cic= in ront o ine $ere u $ant to %ace brea= an" ten
%ress 10. o a"" t$o numbers
*extbox+.text = $onert.*oint+,(textbox1.text) -$onert.*oint+,(textbox,.text);
!n '#
*extbox+.text=$onert.*ostring($onert.*oint+, (textbox1.text) -$onert.*oint+,(textbox,.text));
!n Vb.net t+%e casting is automatic but in '# $e ave to "o it manua+.
o use common an"e i.e. one %roce"ure an"ing more ten one event $e a""
an"es in te en" o %roce"ure in Vb.net i=e
andles button+.$li$%/button0.$li$%/ button.$li$%
!" sender is button + t&enSum
Else i" sender is button0 t&en'ul
Else2iide
!n '#
(e cange in >/L, use on'ic= meto" or tis %ur%ose
- @ -
-
8/9/2019 ASP Net Notes1
8/173
Some %eo%e i=e VB.&7s natura anguage, case-insensitive a%%roac, oters i=e '#sterse s+nta. But bot ave access to te same rame$or= ibraries. (e $i "iscuss about
te "ierences in te oo$ing to%ics
1. A"vantages o bot anguages2. Me+$or" Dierences
;. Data t+%es Dierences
. *%erators Dierences
. Programming Dierence
A$%ata&es o! 1oth #a&ua&es
VB.&7 '#
Su%%ort or o%tiona %arameters - ver+
an"+ or some '*/ intero%erabiit+.
Su%%ort or ate bin"ing $it *%tion Strict
o - t+%e saet+ at com%ie time goes out o
te $in"o$, but egac+ ibraries $ic "ont
ave strong+ t+%e" interaces become
easier to use. Su%%ort or name" in"eers.
Various egac+ VB unctions %rovi"e" in
te 'i$roso"t.Visual#asi$names%ace,
an" can be use" b+ oter anguages $it a
reerence to teMicrosoft.VisualBasic.dll6.
/an+ o tese can be armu to%erormance i use" un$ise+, o$ever, an"
man+ %eo%e beieve te+ sou" be avoi"e"
or te most %art.
e wit&construct its a matter o "ebate
as to $eter tis is an a"vantage or not,but its certain+ a "ierence.
Sim%er in e%ression - %era%s more
com%icate" in un"erstan"ing6 event
an"ing, $ere a meto" can "ecare tat it
an"es an event, rater tan te an"eraving to be set u% in co"e.
X/L "ocumentation generate" rom
source co"e comments. is is comingin VB.&7 $it (i"be+ te co"e
name or te net version o Visua
Stu"io an" .&76, an" tere are toos
$ic $i "o it $it eisting VB.&7
co"e area"+.6 *%erator overoa"ing - again, coming to
VB.&7 in (i"be+.
Language su%%ort or unsigne" t+%es
+ou can use tem rom VB.&7, but
te+ arent in te anguage itse6. Again,
su%%ort or tese is coming to VB.&7 in(i"be+.
7%icit interace im%ementation, $ere
an interace $ic is area"+
im%emente" in a base cass can be re-
im%emente" se%arate+ in a "erive"cass. Arguab+ tis ma=es te cass
ar"er to un"erstan", in te same $a+tat member i"ing norma+ "oes.
nsae co"e. is ao$s %ointer
aritmetic etc, an" can im%rove
%erormance in some situations.
- N -
-
8/9/2019 ASP Net Notes1
9/173
e VB.&7 %arts o Visua Stu"io .&7
com%ies +our co"e in te bac=groun".
(ie tis is consi"ere" as an a"vantage orsma %ro5ects, %eo%e creating ver+ arge
%ro5ects ave oun" tat te !D7 so$s
"o$n consi"erab+ as te %ro5ect gets arger.
>o$ever, it is not to be use" igt+, as a
ot o te norma saet+ o '# is ost as
te name im%ies6. &ote tat unsae co"eis sti manage" co"e, i.e., it is com%ie"
to !L, 4!te", an" run $itin te 'L).
2eywor$ Di!!ereces
Pur%ose VB.&7 '#
Decare a variabe Priate, Publi$, 3riend,
Prote$ted, Stati$1,
S&ared, 2im
de$larators=e+$or"s incu"e user-
"eine" t+%es an" buit-in t+%es6
Decare a name"
constant
4onst $onst
'reate a ne$ ob5ect ew, 4reate5b6e$t() new
-
8/9/2019 ASP Net Notes1
10/173
!nitiai?e a variabe
$ere it is "ecare"
2im x >s Long = 2im $ >s ew _4ar(3uel*7peEnum.8as)
?? initialie to a alue@int x = 1,+;?? or use de"ault?? $onstru$tor@int x = new int();
a=e te a""ress o a
unction
>ddress5"
-
8/9/2019 ASP Net Notes1
11/173
Decare a cass
constant
4onst $onstA%%ie" to a ie" "ecaration6
Derive a cass rom abase cass
!n&erits 4, $lass 41 @ 4,
*verri"e a meto" 5errides oerride
Decare a meto" tat
must be im%emente"in a "eriving cass
'ust5erride abstra$t
Decare a meto" tat
cant be overri""enot5erridable/eto"s
are not oerridableb+
"eaut.6
sealed
Decare a virtua
meto", %ro%ert+
Visua Basic6, or%ro%ert+ accessor
'#, 'CC6
5erridable irtual
>i"e a base cass
member in a "erive"cass
S&adowing n3a
Decare a t+%esae
reerence to a cass
meto"
2elegate delegate
S%eci+ tat a
variabe can contain
an ob5ect $ose
events +ou $is toan"e
Ait&Eents (rite co"e - no s%eciic =e+$or"6
S%eci+ te events or
$ic an event%roce"ure $i be
cae"
andles7vent %roce"ures
can sti be associate" $it a
Ait&Eentsvariabe b+
naming %attern.6
n3a
7vauate an ob5ecte%ression once, in
or"er to access
muti%e members
Ait& ob6Expr.memberlso II
Sortcircuite" Booean*)
5rElse JJ
Sco%e resoution . .an" base
Arra+ eement () 9 :
+%e cast 4int, 42bl, ..., 4*7pe (t7pe)
Posti increment n3a --
Posti "ecrement n3a
!n"irection n3a unsae mo"e on+6
A""ress o >ddress5" Iunsae mo"e on+R aso see
ie"6Logica-&* ot K
*nes com%ement ot M
Prei increment n3a --
Prei "ecrement n3a
Si?e o t+%e n3a sieo"
Bit$ise-A&D >nd I
Bit$ise-ecusive-*) Nor H
Bit$ise-incusive-*) 5r J
Logica-A&D>nd II
Logica-*) 5r JJ
'on"itiona !" 3un$tion () O@
Pointer to member n3a .nsae mo"e on+6
*ro&rammi& Di!!erece
- 1 -
-
8/9/2019 ASP Net Notes1
15/173
Pur%ose VB.&7 '#
Decaring
Variabes
2im x >s !ntegerPubli$ x >s !nteger = 1
int x;int x = 1;
'omments D $ommentx = 1 D $omment
Cem $omment
?? $omment? multiline
$omment ?Assignment
Statements
nVal = Q nVal = Q;
'on"itiona
Statements
!" n4nt = n'ax *&en D Same as n*otal =
D n*otal - n4nt. n*otal -= n4nt
D Same as n4nt = n4nt - 1. n4nt -= 1Else n*otal -= n4nt n4nt = 1End !"
i" (n4nt = n'ax){ n*otal -= n4nt; n4nt--;else{ n*otal -=n4nt; n4nt;
Seection
Statements
Sele$t 4ase n 4ase 'sg#ox (ReroR)
D Visual #asi$ .E* exits D t&e Sele$t at
D t&e end o" a 4ase. 4ase 1 'sg#ox (R5neR) 4ase ,
'sg#ox (R*woR) 4ase Else 'sg#ox (R2e"aultR)End Sele$t
swit$&(n){ $ase @4onsole.AriteLine(ReroR); brea%; $ase [email protected](R5neR); brea%; $ase ,@4onsole.AriteLine(R*woR);
brea%; de"[email protected](ROR); brea%;
s !nteger = 1
publi$ Sub *est() S7stem.4onsole.AriteLine( _ R*est in #ase4lsR)
publi$ $lass #ase4ls{ ?? *&e element to be&idden publi$ int = 1;
publi$ oid *est()
- 1 -
-
8/9/2019 ASP Net Notes1
16/173
End SubEnd 4lass
Publi$ 4lass 2er4ls !n&erits #ase4ls D *&e s&adowing element.
Publi$ S&adows >s String =RR publi$ S&adows Sub *est() S7stem.4onsole.AriteLine( _ R*est in 2er4lsR) End SubEnd 4lass
Publi$ 4lass Bse4lasses D 2er4ls widens to #ase4ls.2im #5b6 >s #ase4ls =
ew 2er4ls() D >$$ess t&roug& deriedD $lass.
2im 25b6 >s 2er4ls =ew 2er4ls()
Publi$ Sub S&ow() S7stem.4onsole.AriteLine( _ R>$$essed t&roug& base RI_ R$lass@ R I #5b6.) S7stem.4onsole.AriteLine(_ R>$$essed t&roug& deried RI_ R$lass@ R I 25b6.) #5b6.*est() 25b6.*est() End Sub
End 4lass
{S7stem.4onsole.AriteLine( R*est in #ase4lsR);
publi$ $lass 2er4ls @#ase4ls{ ?? *&e &iding element publi$ new string = RR; publi$ new oid *est() {S7stem.4onsole.AriteLine( R*est in 2er4lsR);
publi$ $lass Bse4lasses{ ?? 2er4ls widens to#ase4ls #ase4ls #5b6 = new2er4ls();
?? >$$ess t&roug& deried ??$lass2er4ls 25b6 = new
2er4ls();publi$ oid S&ow()
{
S7stem.4onsole.AriteLine( R>$$essed t&roug& R - Rbase $lass@ {R/
#5b6.);S7stem.4onsole.AriteLine( R>$$essed t&roug&R - R deried $lass@{R/ 25b6.); #5b6.*est(); 25b6.*est();
(>!L7Loo%s
D *est at start o" loopA&ile n 1 . D Same as n = n - 1. n -= 1End A&ile D
w&ile (n 1) n--;
- 1: -
-
8/9/2019 ASP Net Notes1
17/173
Parameter
Passing b+
Vaue
D *&e argument T isDpassed b7 alue.Publi$ Sub >#4( _ #7Val 7 >s Long)D!" >#4 $&anges 7/ t&eD $&anges do not a""e$t x.
End Sub>#4(x) D 4all t&e pro$edure.D Tou $an "or$e parameters toD be passed b7 alue/D regardless o" &owD t&e7 are de$lared/D b7 en$losingD t&e parameters inD extra parent&eses.>#4((x))
? ote t&at t&ere isno wa7 to pass re"eren$et7pes (ob6e$ts) stri$tl7b7 alue. Tou $an $&ooseto eit&er pass t&e re"eren$e(essentiall7 a pointer)/ or
a re"eren$e to t&e re"eren$e(a pointer to a pointer).??? *&e met&od@oid >#4(int x){ ...?? 4alling t&e met&od@>#4(i);
ParameterPassing b+
)eerence
Publi$ Sub >#4(#7Ce" 7 >s Long)D *&e parameter 7 is de$laredDb7 re"ere$e@D !" >#4 $&anges 7/ t&e $&angesareD made to t&e alue o" x.End Sub
>#4(x) D 4all t&e pro$edure.
? ote t&at t&ere is nowa7 to pass re"eren$e t7pes(ob6e$ts) stri$tl7 b7alue.Tou $an $&oose to eit&erpass t&e re"eren$e(essentiall7 a pointer)/or a re"eren$e to t&ere"eren$e (a pointer to apointer).??? ote also t&at unsa"e 4U??met&ods $an ta%e pointers??6ust li%e 4-- met&ods. 3or??details/ see unsa"e.?? *&e met&od@oid >#4(re" int x)
{ ...?? 4alling t&e met&od@>#4(re" i);
Structure"
7ce%tion>an"ing
*r7 !" x = *&en *&row ew Ex$eption( _ Rx euals eroR) Else *&row ew Ex$eption( _ Rx does not eual eroR) End !"
4at$& err >s S7stem.Ex$eption 'sg#ox( _ RError@ R I Err.2es$ription)3inall7 'sg#ox( _ RExe$uting "inall7 blo$%.R)End *r7
?? tr7$at$&"inall7tr7{ i" (x == ) t&row newS7stem.Ex$eption( Rx euals eroR); else
t&row newS7stem.Ex$eption( Rx does not eualeroR);$at$& (S7stem.Ex$eption err){ S7stem.4onsole.AriteLine( err.'essage);
- 1@ -
-
8/9/2019 ASP Net Notes1
18/173
"inall7{ S7stem.4onsole.AriteLine( Rexe$uting "inall7blo$%R);
Set an*b5ect
)eerence
to &oting
o = ot&ing o = null;
!nitiai?ing
Vaue +%es
2im dt as ew S7stem.2ate*ime( _ ,1/ 0/ 1,/ ,,/ 1W/ 0X/ Y00)
S7stem.2ate*ime dt =new S7stem.2ate*ime(,1/ 0/ 1,/ ,,/ 1W/
0X/ Y00);
New Features o! 1oth #a&ua&es i +,,3 %ersio
VB.&7 '#
Visua Basic 200 as man+ ne$ an" im%rove"
anguage eatures -- suc as ineritance,
interaces, overri"ing, sare" members, an"
overoa"ing -- tat ma=e it a %o$eru ob5ect-oriente" %rogramming anguage. As a Visua
Basic "eveo%er, +ou can no$ createmutitrea"e", scaabe a%%ications usinge%icit mutitrea"ing. is anguage as
oo$ing ne$ eatures,
1. 4ontinueStatement, $ic
imme"iate+ s=i%s to te net iteration
o a 2o, 3or, or A&ileoo%.
2. !soto%erator, $ic +ou can avoi"
(it te reease o Visua Stu"io 200,
te '# anguage as been u%"ate" to
version 2.0. is anguage as oo$ing
ne$ eatures
1. 4eerics ty"esare a""e" to teanguage to enabe %rogrammers
to acieve a ig eve o co"e
reuse an" enance" %erormanceor coection casses. eneric
t+%es can "ier on+ b+ arit+.
Parameters can aso be orce" tobe s%eciic t+%es.
- 1N -
-
8/9/2019 ASP Net Notes1
19/173
using te otan" !so%erators in an
a$=$ar" or"er.
;. Bsing...End. Bsingstatement boc=
ensures "is%osa o a s+stem resource
$en +our co"e eaves te boc= or
an+ reason.0. Publi$ Sub setbigbold( _. #7Val $ >s 4ontrol)W. Bsing n" >s ew _Q. S7stem.2rawing.3ont(R>rialR/_Y. 1,.3/ 3ontSt7le.#old)X. $.3ont = n"1. $.*ext = R*&is isR I_11. R1,point >rial boldR1,. End Bsing
End Sub
1;. /"#icit 5ero Lower Bou$ o a
Array, Visua Basic no$ %ermits an
arra+ "ecaration to s%eci+ te o$erboun" 06 o eac "imension aong $it
te u%%er boun".1. Usi&e$ Ty"es, Visua Basic no$
su%%orts unsigne" integer "ata t+%es
BS&ort, B!nteger, an" BLong6 as $e
as te signe" t+%e S#7te.
1. O"erator O%er#oa$i&, Visua Basic
no$ ao$s +ou to "eine a stan"ar"o%erator suc as -, I, ot, or 'od6 on a
cass or structure +ou ave "eine".
1:. *artia# Ty"es, to se%arate generate"co"e rom +our autore" co"e into
se%arate source ies.
1@. Visua Basic no$ su%%orts t+%e%arameters on generic casses,
structures, interaces, %roce"ures, an"
"eegates. A corres%on"ing t+%e
argument s%eciies at com%iation timete "ata t+%e o one o te eements in
te generic t+%e.
1N. Custom %ets. ou can "ecare
custom events b+ using te 'ustom=e+$or" as a mo"iier or te Eent
statement. !n a custom event, +ous%eci+ eact+ $at a%%ens $en
co"e a""s or removes an event an"er
to or rom te event, or $en co"eraises te event.
1O. Com"i#er Checki& O"tios, e
2. Iteratorsma=e it easier to "ictate
o$ a or eac oo% $i iterate
over a coections contents.+. ?? !terator Example0. publi$ $lass um4&ar. {
W. string9: saum = {Q. R5neR/ R*woR/ R*&reeR/Y. R3ourR/ R3ieR/ RSixR/X. RSeenR/ REig&tR/ RineR/1. ReroR;11. publi$1,.
S7stem.4olle$tions.!Enumerator
1+. 8etEnumerator()10. {1. "orea$& (string num in
saum)
1W. 7ield return num;1Q. 1Y. 1X. ?? 4reate an instan$e o",. ?? t&e $olle$tion $lass,1. um4&ar oum4&ar = new
um4&ar();,,. ?? !terate t&roug& it wit&
"orea$&,+. "orea$& (string num in
oum4&ar),0. 4onsole.AriteLine(num);
2. Partialt+%e "einitions ao$ a
singe t+%e, suc as a cass, to bes%it into muti%e ies. e VisuaStu"io "esigner uses tis eature to
se%arate its generate" co"e rom
user co"e.2:. Nullablet+%es ao$ a variabe
to contain a vaue tat is
un"eine".2@. Anonymous6etho$is no$
%ossibe to %ass a boc= o co"e as
a %arameter. An+$ere a "eegate
is e%ecte", a co"e boc= can beuse" instea" ere is no nee" to
"eine a ne$ meto".,Y. button1.4li$% -=,X. delegate
{ 'essage#ox.S&ow(R4li$%KR) ;
;0. . e ames"ace a#ias -ua#i!ier
@@6 %rovi"es more contro over
- 1O -
-
8/9/2019 ASP Net Notes1
20/173
3no$arn an" 3$arnaserror o%tions
%rovi"e more contro over o$
$arnings are an"e". 7ac one o tesecom%ier o%tions no$ ta=es a ist o
$arning !Ds as an o%tiona %arameter,
to s%eci+ to $ic $arnings te o%tiona%%ies.
20. ere are eigt ne$ comman"-ine
com"i#er o"tios(
a. e7co$e"a&eo%tion s%eciies$ic co"e%age to use $en
o%ening source ies.
b. e 7$oco%tion generates anX/L "ocumentation ie base"
on comments $itin +our co"e.
c. e 7errorre"orto%tion
%rovi"es a convenient $a+ tore%ort a Visua Basic interna
com%ier error to /icrosot.
". e7!i#ea#i&o%tion s%eciieste si?e o sections in +our
out%ut ie.
e. e 7oco!i&o%tion causes tecom%ier to ignore te Vbc.rsp
ie.
. e 7ost$#i1o%tion %reventste im%ort o mscorlib.dll,
$ic "eines te entire S+stemnames%ace.
g. e 7"#at!ormo%tion s%eciies
te %rocessor to be targete" b+
te out%ut ie, in tose
situations $ere it is necessar+to e%icit+ s%eci+ it.
. e 7ui!yo%tion su%%resses
$arnings resuting rom a
mismatc bet$een te versions
o "irect+ an" in"irect+reerence" assembies.
accessing names%ace members.
e goba @@aias ao$s to
access te root names%ace tatma+ be i""en b+ an entit+ in +our
co"e.
;1. Staticc#assesare a sae an"convenient $a+ o "ecaring a
cass containing static meto"s
tat cannot be instantiate". !n '#v1.2 +ou $ou" ave "eine" te
cass constructor as %rivate to
%revent te cass being
instantiate".;2. N. ere are eigt ne$ com"i#er
o"tios
a. 7#a&%ersio o%tion 'an
be use" to s%eci+com%atibiit+ $it a
s%eciic version o teanguage.
b. 7"#at!ormo%tion 7nabes
+ou to target !P< !A: or!tanium6 an" A/D:
arcitectures.
c. 8"ra&ma$arning se" to
"isabe an" enabein"ivi"ua $arnings in
co"e.". 7#ikresourceo%tion
'ontains a""itiona
o%tions.
e. 7errorre"orto%tion 'anbe use" to re%ort interna
com%ier errors to
/icrosot over te
!nternet.
. 7keycotaieran"
7key!i#e Su%%orts%eci+ing cr+%togra%ic
=e+s.
- 20 -
-
8/9/2019 ASP Net Notes1
21/173
VALIDATION AND C9C2)
Vai"ations are %rovi"e" b+ /icrosot in Vb.net
)un on cient site.
!n as% 4avaScri%t $i not run i cient site "ont ave 4avaScri%t
!n .net i not 5scri%t at cient ten te+ run on server.
Ty"es o! %a#i$ators
ere are : t+%es o vai"ators
)eGuire" ie" vai"ator or em%t+ cec=6.
'om%are vai"ator. (e can com%are
contros i=e %ass$or" n conirm %ass$or"6
vaue age must be greater ten 1N6
"ata t+%e cec= saar+ must be no.6
)ange vai"ator
)eguar e%ression vai"ator
Pre "eine ormat vai" emai a""ress6
- 21 -
-
8/9/2019 ASP Net Notes1
22/173
'ustom vai"ator
Vai"ation summar+
(eb.!.Vai"ation.5s is te ie name in $ic 5scri%t o a tese vai"ator are
avaiabe.
(e not abe to associate contros $it vai"ators in ASP.&et 1.1 but can "o tis in
2.0 7.g. 8username n %ass9 an" searc is cec= b+ "ierent button.
Re-uire$ !ie#$ %a#i$atio "ro"erties
controoVai"atename o tetbo to cec=
et message
Com"are %a#i$atio "ro"erties
controoVai"atename o irst tetbo to cec=
et
message controoVai"atename o secon" tetbo to cec=
-
8/9/2019 ASP Net Notes1
23/173
Va#i$atio summary
7= 5aga sare error n asteris= sign in ront o error
et %ro%ert+ vaue "is%a+ on vai"ator an" error message "is%a+ on te vai"ation
summar+.
et Terror/essage 7m%no em%t+
o run vai"ation summar+ $e nee" a button
o ma=e %o%u% $in"o$ go to vai"ation summar+ %ro%ert+
So$/essageBotrue
So$ Summar+ ase
A""ition %ro%erties in version 2.0
set te causes vai"ation %ro%ert+ to ase to "isabe te vai"ation o button
vai"ation grou% %ro%ert+ o vai"ator tetbo, vai"ationSummar+ n o button6
o Vai"ationrou% a %ro%ert+ o vai"ator
o Setocuson7rrorto go "irect+ to te error %oint s=i% correct %aces.
A"" more tan one %age in $ebsite 'ic= on $ebsite a"" ne$ item $eborm6
o /a=e startu% %age go to soution e%orerrigt cic= on %age set as start
%age6.
o go to ne$ %age $e ave ; meto"s
o )es%onse.re"irect6
o Server.transer6
o Server.eecute6
o go to net %age b+ button
o )es%onse.re"irect8"eaut.as%96
o go to net %age b+ +%erin= %ro%erties
o et net
o &avigate )L"eaut.as%
(en $e $ant to move to net %age $itout submitting te current %age $e use
+%erin=.
Basic Cotro#s i .et
cec=bo
$&e$%box1_$&e$%ed $&anged eent{
!"($&e$%box.$&e$%ed == true){
- 2; -
-
8/9/2019 ASP Net Notes1
24/173
*extbox1."ont.bold = true;Else{
*extbox1."ont.bold = "alse;
o $eb server contro as %ro%ert+
autoPostBac=to ma=e te %age submit $en tere vaue canges
co? a $eb server contro acce%t vaue ater cic=ing
on button.
)a"io button
o Pro%ert+ rou%&ame to mention te grou%.
o e+ ave on+ seecte" $enever $e cic= on tem not ic= cec=bo.
radiobutton_$&e$%ed $&anged eent{
*extbox1."ore$olor = $olor.red
o (e must incu"e a names%ace to use coor
sing S+stem.Dra$ingR
'ec=bo ist
o DataBoun" contro it is coection o cec=boes
o seu $en $e $ant to ma=e cec=boes at runtime.
o Pro%erties
)e%eat coumns vaue
)e%eat "irection vertica3 ori?onta
o ; meto" o "eining te cec=boes
7"it items Seecte" b+ "eaut seecte"
7nabe" "isabe to user to cange it
)un time "ata entr+Page_load{
!"(page.isPost#a$% == "alse)
- 2 -
-
8/9/2019 ASP Net Notes1
25/173
{4&e$%boxlist1.itms.add(Zab$[);4&e$%boxlist1.itms.add(Zx7[);
/* For collection We must have namespace
Using System.collection
!ollection is data structure to store items
"rraylist
array of ob#ects $hich increase its si%e dynamically.
by default has si%e e&ual to ' characters.
*/
>rra7list arr = new >rra7List();arr.add(Zab$[);
arr.add(Zx7);
$&e$%boxlist1.dataSour$e = arr;$&e$%boxlist1.data#ind();
// both these methods $or( together
4&e$%boxlist1.items9:.enabled = "alse;
#utton1_$li$%{
3or(int+, i=;i$&e$%boxlist1.items.$ount; i--){
!"($&e$%boxlist1.item9i:.sele$ted==true)*extbox1.text-=$&e$%boxlist1.item9i:.
text -[Fn[;
etbo %ro%ert+
etmo"e muti%e ine to "is%a+ "ata in muti%e ine6
o store "ierent vaue in cec=bo at bein"
i""en name vaue, "is%a+ nametet6
o a"" vaue ie"
- 2 -
-
8/9/2019 ASP Net Notes1
26/173
'ec=boist1.items.a""ne$ ist!tem8aa9,91966Ro retrieve vaue
'ec=boist1.itemsUi.vaueR
DATABA) 9ANDLIN4
Dierence bet$een /sAccess an" SQL
!n orace K SQL tere are triggers, %roce"ure, unctions, cursor genera+ =no$ as
com%ie ob5ects $ic are store in "atabase an" eecute" in "atabase on+ "ue to
$ic traic $i not so$ "o$n. Database server an" a%%ication server are t$o "ierent tings.
Store %roce"ure once eecute", net time te %roce"ure $i be aster tan beore.
Less s%ace in access.
Less securit+ in access.
*race is OO.OW use" b+ te tose com%anies $ic ave o$n server.
!n (eb "eveo%ment OOW $e use SQL.
- 2: -
-
8/9/2019 ASP Net Notes1
27/173
ADO.Net ActiveX Data *b5ect6
!t is an environment $ic is "esign b+ /icrosot or "atabase an"ing.
$o main com%onents
o X/L it is incense ree, %atorm in"e%en"ent an" te astest $a+ o "atatranser 6.
o Disconnecte" a%%roac "ata is co%ie" at a%%ication server an" te connect
$it te "atabase server is "isconnecte" so tat origina "ata $i remainuntouce"6.
!t "esign $ie aving $eb a%%ication in min".
Data1ase coecti%ity
ere are $a+s o connectivit+ $it "atabase
o *DB' *%en DataBase 'onnectivit+6 Used to connect to each n
o *L7DB *b5ect Lin=ing K 7mbe""ing6 every server
o SQL'ient s%eciica+ use" $it /s SQL server. !t is incu"e" in .net6
o *)A'L7'ient s%eciica+ use" $it *race server. !t is incu"e" in .net6
Better performance and !ompatibility
$o main ies are tere
o .m" /icrosot "atabase ie6o ." og "atabase ie6
o create "atabase
o Vie$server e%orer
o !n ast tere is 8server9 to =no$ te server name
o Data connectionrigt cic=6 create ne$ SQL server DB
o /ention tese ie"s
Server namesac
se SQL server autentication
sername
8sa9 "eaut6 &e$ "atabase name "bem%o+ee
o &o$ tis "bem%o+ee $i be a""e" in "ata connection
o Sac."bem%o+ee taberigt cic=6 a"" ne$ tabe
o /ention coumn name an" "ata t+%e as
7no int
7name varcar06
- 2@ -
-
8/9/2019 ASP Net Notes1
28/173
7a""ressvarcar06
7sa int
Dierence bet$een varcar an" nvarcar is tat varcar uses AS'!! an" nvarcar
uses nico"e.
(eb.conig ie
o !t is use" to store connection string. !t is to mani%uate it i server name, ui"canges instea" o going to eac n ever+ %age $e 5ust cange it in $eb.conig.
o &on com%ie ie $ere as mo"ue as to com%ie
o X/L base", 'ase sensitive
o Secure in version 2.0 $e cant vie$ te ie $itout co"ing6
o !nteigence e% is %rovi"e" in version 2.0
o !t can be muti%e in singe %ro5ect but macine.conig is singe in one %ro5ect.
o !t is or %ro5ect coniguration e.g. securit+ setting, session setting etc
o o a"" $eb.conig
(ebsitea"" ne$ item$eb con ie
o A"" connection string in tis ieconnection stringY
a"" nameZ9nonu9 connectionStringZ9serverZsacR "atabaseZ"bem%o+eeR
(ey
ui"ZsaR %$"Za"min93Y
)t is used if u have
mentioned pass$ord
3connection stringY
o Server name in connection string is not com%usor+ i ur server is sames+stem $ere a%%ication is running.
o !n 1.0 $e a"" connection string in a%%settingsY tag
7g. a"" =e+Z9cs9 vaueZ9"atabaseZ"bem%Rui"Zsa9Y
An" 7cess tis as conigurationSetting.A%%SettingsU8cs9
Dierence bet$een
o >as stores =e+ as $e as vaue
o Arra+stores on+ vaue
(e sou" a""
Bsing S7stem.data.S\L4lient;4lass_de"ault{ S\L4onne$tion $on = new S\L4onne$tion();
// S+!onnection class is used to establish connection
Page_load
- 2N -
-
8/9/2019 ASP Net Notes1
29/173
{ *&is.smartaigation = true;
// in c, $e use -this and in VB.et $e use -me
4on.$onne$tionString =
4on"iguration'anager.4onne$tionString9Znonu[:. $onne$tionString;
// !onfigurationManager is used to read connection string.
!" ($on.State ==4onne$tionState.4losed){
4on.open();
// open01 ma(e connection active 2 ma(e connectivity $ith S+ server.// before using open01 $e must chec( the state of connection other$ise
problem of connection pooling occur.
// run this much if it page opens that means connectivity is o(
// don3t insert control directly on page co% it $ill not loo( going $hen the resolution
changes.
!"(page.isPost#a$% == "alse)textbox1.text=get>uto().toString();
#utton1_$li$% // save
{S\L$ommand $md = new sl$ommand();
// S+!ommand bridge bet$een data and database. Used for save4 delete4 update4
display $md.4ommand*ext.=[!nsert into t&emp
alues(]eno/]en/]ed]es)[;
// command5e6t is used to specify &uery or store procedure4 7eno are parameters $ith
are used at runtime
$md.$ommand=$on;
// connection established
$md.parameters.add(Z]eno[/sldbt7pe.!nt).alue =$onert.*o!nt+,(textbox1.text);
- 2O -
-
8/9/2019 ASP Net Notes1
30/173
-
8/9/2019 ASP Net Notes1
31/173
$onert.*o!nt+,(textbox1.text);$md.parameters.add(Z]en[/sldbt7pe.Var$&ar/ ).
alue =textbox,.text;$md.exe$uteon\uer7();
$md.dispose();
textbox1.text = Z Z;textbox,.text = Z Z;textbox+.text = Z Z;textbox0.text = Z Z;
Dis"#ay co$e
#utton0_$li$%{
S\L$ommand $md = new sl$ommand();$md.$ommand*ext =[sele$t "rom tbemp[;$md.$onne$tion = $on;
S\L2ataCeader dr;
/*
S+9ata:eader is used to vie$ data4
)t is read only.
For$ard only 0 only go in for$ard direction1
)t is the fastest $ay of data retrieval. Se&uential read.
o need of -ne$ operator.
)t is segantal class used to pass reference #ust li(e abstract class.
We should close it after using it co% other$ise $e can3t use it again li(e static
method it has only one memory.
*/
2r = $md.Exe$uteCeader ();
// 86ecute:eader #ust e6ecute the &uery n store the data in variable0#ust for display1
Listbox1.data*ext3ield =[ename[;
// 9ata5e6tField display the data in listbo6
Listbox1.dataValue3ield =[empno[;
// value at the bac( side of listbo6 0not visible1
- ;1 -
-
8/9/2019 ASP Net Notes1
32/173
Listbox1.2ataSour$e = dr;Listbox1.2ata#ind();
2r.$lose();
$md.dispose();
Set te autoPostBac= %ro%ert+ o istbo1 eGua to true.
Listbox1_sele$ted!ndex4&anged{
S\L$ommand $md = new sl$ommand ();$md.$ommand*ext=[sele$t "rom dbemp w&ere empno =
]eno[;$md.$ommand=$on;$md.parameters.add (Z]eno[/ sldbt7pe.!nt).alue =
$onert.*o!nt+, (listbox1.sele$tedValue);
$md.parameters.add (Z]eno[/ sldbt7pe.!nt).alue = $onert.*o!nt+, (listbox1.sele$ted!tem.text);
// selectedValue to get the value behind the data selected
// selected)tem.te6t to get the value display in the listbo6
Sl2ataCeader dr;2r = $md.Exe$uteCeader();
!"(dr.asCows){
2r.Cead(); // to read the ne6t line*extbox1.*ext = dr 9Zempno[:.*oString();*extbox1.*ext = dr 9Zename[:.*oString();*extbox1.*ext = dr 9Zeaddress[:.*oString();*extbox1.*ext = dr 9Zesal[:.*oString();
// convert the data to string co% by default they are ob#ects
2r.$lose();$md.dispose();
o generate te auto numbers i=e account no., em%no
Priate !nt+, get>uto(){
- ;2 -
-
8/9/2019 ASP Net Notes1
33/173
S\L$ommand $md = new sl$ommand (); $md.$ommand*ext=[sele$t isull(max(empno)/ ) "rom
tbemp[;
$md.$onne$tion = $on;
!nt+, r = $onert.*o!nt+,($md.exe$uteS$alar()) - 1;
// e6ecuteScalar for &uery $hich return single value4 if multiple value is there
then
)t returns first column3s fist value.
$md.dispose();Ceturn r;
)TOR *ROCDUR)
e+ can %ass maimum 102 numbers o %arameters
ere are ; t+%es o %arameters
o !n%ut 5ust to %ass te vaue6
o *ut%ut 5ust to return te vaue6
o !n%ut3out%ut $e can %ass as $e as return vaue6
e+ can return vaue
Pre com%ie ob5ects
- ;; -
-
8/9/2019 ASP Net Notes1
34/173
Dierence bet$een unction an" %roce"ure
o *E PC54E2BCE insemp(
]eno int/]en ar$&ar()/]ed ar$&ar()/]es int
)>S
!nsert into tbemp alues(]eno/]en/]ed/]es)
(en $e save tis ')7A7 $i automatica+ canges to AL7) tat means in
uture $e can on+ ater tis %roce"ure.
! $e "ont s%eci+ te si?e in varcar ten it $i store on+ one caracter.
U"$ate "roce$ure
4CE>*E PC54E2BCE updemp(
]eno int/]en ar$&ar()/]ed ar$&ar()/]es int
)
- ; -
-
8/9/2019 ASP Net Notes1
35/173
>SBpdate tbemp set ename = ]en/ eaddress = ]ed/ esal =
]es w&ere empno = ]eno
De#ete "roce$ure
4CE>*E PC54E2BCE delemp(
]eno int)>S
2elete tbemp w&ere empno = ]eno.
Dis"#ay "roce$ure
4CE>*E PC54E2BCE dispemp>S
Sele$t "rom tbemp.
Fi$ "roce$ure
4CE>*E PC54E2BCE "indemp(
]eno int)>S
Sele$t "rom tbemp w&ere empno = ]eno
(e can store more tan one Guer+ in one %roce"ure $en $e "o more tan one $or=
in a singe ste% i=e $en $e cic= on button ten Save n %"ate $i run
simutaneous.
Autheticatio "roce$ure
'reate tabe tbuser6
o name varcar06
o %ass varcar06
4CE>*E PC54E2BCE login4&e$%(]u ar$&ar()/]p ar$&ar()
)>S
2e$lare ]ap ar$&ar()SELE4* ]ap = upass "rom tbuser w&ere uname = ]u
- ; -
-
8/9/2019 ASP Net Notes1
36/173
!" ]ap is nullCeturn 1
Else!" ]ap = ]p
Ceturn 1ElseCeturn ,
! $e "ont $rite an+ting in ront o %arameter ten b+ "eaut te+ are o t+%e in%ut.
! uname is not vai" ten seect statement return nu in [a%.
&o$ instea" o $riting comman" in ront en" $e $rite tese t$o ines
o 'm".comman"etZ9;rocedure name9R
o 'm".comman"+%eZcomman"+%e.StoreProce"ureR
'omman"+%e tes us te t+%e o comman".
o enter "ata "irect+ to tabe rigt cic= on te tabe in te server e%orer
so$ tabe "ata.
A"" t$o tree accounts in te tabe
Design te ront vie$ "esign o ogin screen
Bsing S7stem.data.S\L4lient;4lass_de"ault{
S\L4onne$tion $on = new S\L4onne$tion;Page_load{
4on.$onne$tionString = $on"iguration'anager. $onne$tionString9Znonu[:.$onne$tionSting;
i" ($on.state = = $onne$tionState.$losed){
4on.open();
Priate !nt+, $&e$%user(String u/ String p){
S\L4ommand $md = new S\L4ommand();$md.$ommand*ext = Zlogin4&e$%[;
$md.$ommand*7pe = $ommand*7pe.StorePro$edure$md.pamameter.add(Z]u[/S\LVb*7pe.ar$&ar/ ).alue=u;
$md.pamameter.add(Z]p[/S\LVb*7pe.ar$&ar/ ).alue=p;
// to receive the value return by procedure $e must ma(e a parameter
S\LParameter p1 = new S\LParameter(Z]ret[/
- ;: -
-
8/9/2019 ASP Net Notes1
37/173
S\L2bt7pe.!nt);P1.2ire$tion = Parameter2ire$tion.returnValue;
// returnValue is the
-
8/9/2019 ASP Net Notes1
38/173
o >ea"er tem%ate
o
-
8/9/2019 ASP Net Notes1
39/173
boo=Pub varcar06
boo=Price int
boo=!mg varcar06// $e can also store this in binary
o A"" t$o tree recor"s in te tabe.
o rgs e){ rep#ind();priate oid rep#ind(){
Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t "rom
tbboo%R/4on"iguration'anager.4onne$tionStrings 9R$sR:.4onne$tionString);
// S&l9ata"dapter al$ays used $ith disconnection approach. )t implicit open 2 close the
!onnection
2ataSet ds = new 2ataSet();
/* 9ataSet
!ollection of table
8&ual to 9ata:eader
We can set the relations
Very important point is that it read and $rite data in =M+ format
5ypes
o 5ype 9ataSet
We define the structure at design time
;erformance is better than untype 9ataSet
We use it in reports or $hen $e (no$ fi6ed no. of columns
86tension.6sd
o Untype 9ataSet
9efine structure at run time
9ata is also added at run time ;erformance is slo$
We use this if $e don3t (no$ fi6ed no of column
*/ adp.3ill(ds);
// Fillcreate connection4 open it4 e6ecute &uery4 put data in 9ataSet close connection
Cepeater1.2ataSour$e = ds; Cepeater1.2ata#ind();
- ;O -
-
8/9/2019 ASP Net Notes1
40/173
o to >/L o "eaut.as%
asp@Cepeater !2=RCepeater1R runat=RsererRsp *ag Pre"ix< K Cepeater *ag amemt(!nt+, pr$)
{ return pr$ 4al2is(pr$);
Tem"#ate
(or=ing an" time o a te tem%ate are ie".
*r"er "oesnt "isturb te $or=ing o tem%ates.
!n item tem%ate
o (e "eine on+ singe ro$ "is%a+ ormat.
o !t $i run again n again accor"ing to te number o ro$s.
>ea"er tem%ate
o !t $i run on+ once or ea"ing
o !ts te irst tem%ate, $ic $i run.
/L.
Aternating item tem%ates $or= $it item tem%ates aternating.
)e%eater me "ierent coumn $aa conce%t nai ota.
Data#ist
o "is%a+ "ata in muti%e coumn.
(e can mani%uate "ata e"it, "eete, u%"ate6
&o %aging.
&o "eaut tem%ate
@ tem%ates are a%%icabe
o !tem tem%ate
o >ea"er tem%ate
o
-
8/9/2019 ASP Net Notes1
43/173
Pace "ataList rom toobo
A"" $eb conig ie an" ma=e connection string.
Bsing S7stem.2ata.Sl$lient;
Priate oid List#ind(){
Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t "rom tbboo%R/4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds); 2ataList1.2ataSour$e = ds; 2ataList1.2ata#ind();
Page_load {
!"(page.isPost#a$%=="alse)List#ind();
!n >/L
asp@2ataList
b
-
8/9/2019 ASP Net Notes1
44/173
o auto ormat cic= on DataList as=s Auto
-
8/9/2019 ASP Net Notes1
45/173
{2ataList1.Edit!tem!ndex = 1;List#ind();
2ataList1_Bpdate4ommand(sour$e/ e){String title/ aut&or/ pub;!nt+, pr$;*itle=((textbox)(e.!tem.3ind4ontrol(Zt1[))).text;>ut&or =((textbox)(e.!tem.3ind4ontrol(Zt,[))).text;Pub =((textbox)(e.!tem.3ind4ontrol(Zt+[))).text;Pr$=4onert.*o!nt+,(((textbox)
(e.!tem.3ind4ontrol(Zt0[))).text);bid = 4onert.*o!nt+,
(2ataList1.2ata`e7s9e.!tem.!tem!ndex:); Sl4onne$tion $on = new Sl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString;
i" ($on.State == 4onne$tionState.4losed)
{ $on.5pen(); Sl4ommand $md = new Sl4ommand();
$md.4ommand*ext = Rupdate tbboo% set boo%*itle=]title/
boo%>ut&or =]aut&or/ boo%Pub=]pub/ boo%Pri$e=]pr$ w&ere boo%!d=]bidR;
$md.4onne$tion = $on;
$md.Parameters.>dd(RtitleR/ Sl2b*7pe.Var4&ar/ ).Value = title;$md.Parameters.>dd(Raut&orR/ Sl2b*7pe.Var4&ar/ ).Value=aut
$md.Parameters.>dd(RpubR/ Sl2b*7pe.Var4&ar/ ).Value = pub;
$md.Parameters.>dd(Rpr$R/ Sl2b*7pe.!nt).Value = pr$; $md.Parameters.>dd(RbidR/ Sl2b*7pe.!nt).Value = bid;
$md.Exe$uteon\uer7(); $md.2ispose();
2ataList1.Edit!tem!ndex = 1; List#ind();
o ma=e "irect connection $it "atabase $itout co"ing $e use SGDataSource
- -
-
8/9/2019 ASP Net Notes1
46/173
o !t is use" $it 2 F tier arcitecture
o $o a+ers in 2 F tier arcitecture are
Data Access La+er
Presentation La+er
o se" or "atabase connectivit+, to rea", insert, u%"ate etc.
Pace SGDataSource rom toobo an" cic= on SGDataSource tas=s
'onigure Data Sourceseect Databasegive name to connectionString mar=
te cec=bo i u $ant tis connection
String sou" a""e" in $eb.conig ie6
Seect tabeten seect coumns ten cic= inis.
'ic= on DataList as=s 'oose Data Source SGDataSource1.
o cec= $eter tis SGDataSource is connecte" or "isconnecte" a%%roac
'ic= on te %ro%erties o SGDataSource DataSource/o"e
Data)ea"erconnecte" a%%roac6 3 DataSet"isconnecte" a%%roac6
!n >/L
!tem*emplate< b
-
8/9/2019 ASP Net Notes1
47/173
asp@Lin%#utton !2=Rlb1R *ext=RBpdateR 4ommandame=
RupdateR runat=serer
-
8/9/2019 ASP Net Notes1
48/173
T3pd = (2ataList1.2ata`e7s9e.item.item!ndex:).*oString();Sl2ataSour$e1.BpdateParameter9Zpid[:.2e"aultValue=pd;Sl2ataSour$e1.update();2atalist1.Edit!tem!ndex = 1;
2atalist1.databind();
- N -
-
8/9/2019 ASP Net Notes1
49/173
:. *RODUCT) WIT9 C9C2BOdapter adp = new Sl2ata>dapter(Rsele$t "rom tbboo%R/4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet(); adp.3ill(ds);
2ataList1.2ataSour$e = ds; 2ataList1.2ata#ind();
#utton_$li$% {
String st=[[;3or(int+, i=; i2ataList.item.$ount;i--;){
$&e$%box $=($&e$%box)(2atalist1.item9!:.3ind4ontrol(Z$b[));
i"($.$&e$%ed ==true)
st -=2ataList1.2ata`e79!:.toString() -[/[;St = st.Substring(/st.lengt&1);
Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t "rom produ$tsw&ere produ$t !n(Z-st-[)[)/4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();adp.3ill(ds);
2ataList,.2ataSour$e = ds;2ataList,.2ata#ind();
!n >/L
asp@2ataList1
b
-
8/9/2019 ASP Net Notes1
50/173
-
8/9/2019 ASP Net Notes1
51/173
:. DI)*LA; )LCTD DATA IN Tdapter adp = new Sl2ata>dapter(Rsele$t "rom tbboo%R/4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2ataList1.2ataSour$e = ds; 2ataList1.2ata#ind();Page_load{
!"(page.isPost#a$%=="alse)List#ind();
2ataList1_Sele$ted!ndex4&anged{ String st;
st = Rsele$t "rom tbboo% w&ere boo%!d=R -2ataList1.2ata`e7s9sele$ted!ndex:.*oString();
Sl2ata>dapter adp = new Sl2ata>dapter(st/ 4on"iguration'anager. 4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet(); adp.3ill(ds); ??*ext#ox1.*ext=ds.*ables9:.Cows9:
9Rboo%*itleR:.*oString(); ??*ext#ox,.*ext = ds.*ables9:.Cows9: 9Rboo%>ut&orR:.*oString();
??*ext#ox+.*ext = ds.*ables9:.Cows9: 9Rboo%PubR:.*oString(); ??*ext#ox0.*ext = ds.*ables9:.Cows9: 9Rboo%PrieR:.*oString();
// 9S is an ob#ect n is very heary so it3s not good to call it again n again. We should use
properties4 method4 variable but not ob#ects
- 1 -
-
8/9/2019 ASP Net Notes1
52/173
2ataCowView r;
339ata:o$Vie$ class only accept single ro$.
r=ds.*ables9:.2e"aultView9:;
*ext#ox1.*ext = r9:9Rboo%*itleR:.*oString(); *ext#ox,.*ext =r9:9Rboo%>ut&orR:.*oString(); *ext#ox+.*ext = r9:9Rboo%PubR:.*oString(); *ext#ox0.*ext = r9:9Rboo%Pri$eR:.*oString();
!n >/L
asp@2ataList
-
8/9/2019 ASP Net Notes1
53/173
:. /L
&ead runat=RsererR< title
-
8/9/2019 ASP Net Notes1
54/173
"un$tion $olor(id) { ar e1;
e1=do$ument.getElement#7!d(D&D-id); i"(e1) { e1.st7le.$olor=DblueD; "or(ar i=;iW;i--) { i"(i==id) { i--; e,=do$ument.getElement#7!d(D&D-i); i"(e,) { e,.st7le.$olor=Dbla$%D; ?s$riptdd(R]pagenumberR/Sl2b*7pe.!nt).Value=pg;
$md.Parameters.>dd(R]pagesieR/ Sl2b*7pe.!nt).Value = nor;
- : -
-
8/9/2019 ASP Net Notes1
57/173
$md.4onne$tion = $on; Sl2ataCeader dr; dr = $md.Exe$uteCeader(); dr.Cead();
!nt+, total/t; total = 4onert.*o!nt+,(dr9:); i" (total G nor == ) { t = 4onert.*o!nt+,(total ? nor); else { t = 4onert.*o!nt+,(total ? nor -1); Label1.*ext = pg.*oString(); Label,.*ext = Ro"R; Label+.*ext = t.*oString();
!nt+, i; >rra7List arr = new >rra7List(); arr.>dd(RR); "or (i = 1; i = 4onert.*o!nt+,(Label+.*ext); i--) { arr.>dd(i.*oString()); arr.>dd(R
-
8/9/2019 ASP Net Notes1
58/173
{ #utton1.Enabled = "alse; #utton,.Enabled = "alse; i" (pg == 4onert.*o!nt+,(Label+.*ext))
{ #utton+.Enabled = "alse; #utton0.Enabled = "alse;
2rop2ownList1_Sele$ted!ndex4&anged(sender/ e) { Page#ind(1);
prote$ted oid #utton1_4li$%(sender/ e)//First { Page#ind(1);
prote$ted oid #utton,_4li$%(sender/ e)//previous { Page#ind(4onert.*o!nt+,(Label1.*ext) 1);
prote$ted oid #utton+_4li$%(sender/ e)//e6t { Page#ind(4onert.*o!nt+,(Label1.*ext) - 1);
prote$ted oid #utton0_4li$%(sender/ e)//+ast { Page#ind(4onert.*o!nt+,(Label+.*ext));
oid 2ataList,_Sele$ted!ndex4&anged(sender/e) { i" (2ataList,.Sele$ted!ndex==) { i" ((4onert.*o!nt+,(Label1.*ext))K= 1) { Page#ind(4onert.*o!nt+,(Label1.*ext) 1);
else i"(2ataList,.Sele$ted!ndex==2ataList,.!tems.4ount1)) { i"((4onert.*o!nt+,(Label1.*ext))K=(2ataList,.!tems.4ount ,)) { Page#ind(4onert.*o!nt+,(Label1.*ext) - 1);
- N -
-
8/9/2019 ASP Net Notes1
59/173
else {
Page#ind(2ataList,.Sele$ted!ndex);
I 9T6L
asp@2ataList !2=R2ataList1R runat=RsererR< !tem*emplate< b< ame@ ?b
-
8/9/2019 ASP Net Notes1
60/173
4RIDVIW
o "is%a+ "ata in ro$s K coumns. (e can mani%uate "ata e"it, "eete, an" u%"ate6.
Auto e"it, "eete, seect
!nbuit %aging
!nbuit sorting
'oumn boun"
N tem%ates are a%%icabe
o !tem tem%ate
o >ea"er tem%ate
o
-
8/9/2019 ASP Net Notes1
61/173
// if parameter name is e&ual to columns name then no need of added
parameter to &uery
o DeeteQuer+
Deete rom tbboo= $ere boo=!"Z[boo=!"
8ridView1_Sele$ted!ndex4&anged(sender/ e){ *ext#ox1.*ext = 8ridView1.Sele$tedCow.4ells91:.*ext; *ext#ox,.*ext = 8ridView1.Sele$tedCow.4ells9,:.*ext; *ext#ox+.*ext = 8ridView1.Sele$tedCow.4ells9+:.*ext; *ext#ox0.*ext = 8ridView1.Sele$tedCow.4ells90:.*ext; *ext#ox.*ext = 8ridView1.Sele$tedCow.4ells9:.*ext;
With Co$i&
Page_Load(ob6e$t sender/ Eent>rgs e){
i" (Page.!sPost#a$% == "alse) { 8rd#ind(); priate oid 8rd#ind(){ Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t "rom tbboo%R/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds); 8ridView1.2ataSour$e = ds; 8ridView1.2ata#ind();prote$ted oid 8ridView1_CowEditing(sender/ e){ 8ridView1.Edit!ndex = e.ewEdit!ndex; 8rd#ind();
8ridView1_Cow4an$elingEdit(sender/ e){ 8ridView1.Edit!ndex = 1; 8rd#ind();8ridView1_CowBpdating(sender/ e){ Sl4onne$tion $on = new Sl4onne$tion();
- :1 -
-
8/9/2019 ASP Net Notes1
62/173
$on.4onne$tionString = 4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); Sl4ommand $md = new Sl4ommand();
$md.4ommand*ext =Rupdate tbboo% set boo%*itle=]title/boo%>ut&or=
]aut&or/ boo%Pub=]pub/ boo%Pri$e=]pri$e w&ere boo%!d=]idR; $md.4onne$tion = $on; $md.Parameters.>dd(R]idR/Sl2b*7pe.!nt).Value= 4onert.*o!nt+,
(((Label)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(RlR))).*ext);
$md.Parameters.>dd(R]titleR/ Sl2b*7pe.Var4&ar/ ).Value =
((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb1R))).*ext;
$md.Parameters.>dd(R]aut&orR/ Sl2b*7pe.Var4&ar/ ).Value =((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb,R))).*ext;
$md.Parameters.>dd(R]pubR/ Sl2b*7pe.Var4&ar/ ).Value =((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb+R))).*ext;
$md.Parameters.>dd(R]pri$eR/Sl2b*7pe.!nt).Value=4onert.*o!nt+,(((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb0R))).*ext);
$md.Exe$uteon\uer7(); $md.2ispose(); 8ridView1.Edit!ndex = 1; 8rd#ind();
8ridView1_Cow2eleting(sender/ e){ !nt+, eno;
// add 9ata?eyame in AridVie$ ;roperty eno = 4onert.*o!nt+,(8ridView1.2ata`e7s 9e.Cow!ndex:9:); Sl4onne$tion $on = new Sl4onne$tion(); $on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext=Rdelete "rom tbboo% w&ere boo%!d=]idR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]idR/Sl2b*7pe.!nt).Value= eno; $md.Exe$uteon\uer7(); $md.2ispose(); 8ridView1.Edit!ndex = 1; 8rd#ind();
- :2 -
-
8/9/2019 ASP Net Notes1
63/173
I 9T6L
asp@8ridView !2=R8ridView1R runat=RsererRlign =
oriontal>lign.4enter; e.Cow.4ells.Cemoe>t(,); e.Cow.4ells.Cemoe>t(1); i" (e.Cow.4ells9:.*ext == RameR) { e.Cow.#a$%4olor = 4olor.4&o$olate;
- :O -
-
8/9/2019 ASP Net Notes1
70/173
:UR; ANAL;5R
seect isnu categor+name,.oata6,isnu %ro"uctname,Sub ota6, sumunit%rice6
unit%rice,sumunitsinstoc=6 unitsinstoc= rom %ro"ucts a, categories b $erea.categor+!"Zb.categor+!" grou% b+ categor+name, %ro"uctname $it rou%
33 Seect me $oi coumn name aa+ege 5o grou% b+ me "eine ote ai33 rou% is a$a+s use $it 8grou% b+9
33 is Guer+ $i re%ace a nu $it 8Sub ota9 it not cec= $ere it is en" o categor+ or nu in %ro"uct name coumn tat + $e use secon" Guer+.
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
seect case $engrou%ingcategor+name6Z16 ten .ota ese categor+name en"
categor+name,case $engrou%ing%ro"uctname6Z16 ten Sub ota ese %ro"uctnameen" %ro"uctname, sumunit%rice6 unit%rice,sumunitsinstoc=6 unitsinstoc= rom %ro"ucts,
sumunit%rice6 unit%rice,sumunitsinstoc=6 unitsinstoc= rom %ro"ucts a, categories b
$ere a.categor+!"Zb.categor+!" grou% b+ categor+name, %ro"uctname $it rou%a, categories b $ere a.categor+!"Zb.categor+!" grou% b+ categor+name, %ro"uctname
$it rou%
- @0 -
-
8/9/2019 ASP Net Notes1
71/173
:. ADD IT6) IN TABL
Pace ri"vie$
A"" (eb conig ie n ma=e connection string
ri"vie$%ro%erties autoenrate'oumns ase
'ic= on te tas=s menu o gri"vie$ 7"it em%ate
'ic= on 7m%no in "is%a+ an" in its em%ate a"" $at so ever contro u $ant
ten cic= on a""e" "ata bin"ings an" $rite co"e in co"e e%ression i=e7va8em%no966
Do same or oter cooums.
(en $e mention comman" name o our coice ten tat is come un"er
)o$'omman" event
using S7stem.2ata.Sl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page{ Sl4onne$tion $on = new Sl4onne$tion();
prote$ted oid Page_Load(ob6e$t sender/ Eent>rgs e) { i" (KPage.!sPost#a$%) { 8rd#ind();
priate oid 8rd#ind() { Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t "rom tbempR/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString); 2ataSet ds = new 2ataSet(); adp.3ill(ds); 8ridView1.2ataSour$e = ds; 8ridView1.2ata#ind(); prote$ted oid 8ridView1_Cow4ommand(sender/ e) {
- @1 -
-
8/9/2019 ASP Net Notes1
72/173
i" (e.4ommandame == Sae) { !nt+, eno/ es; String en/ eadd; eno= 4onert.*o!nt+,(((Label) (8ridView1.3ooterCow.3ind4ontrol(Rlabel+R))).*ext);
es= 4onert.*o!nt+,(((*ext#ox) (8ridView1.3ooterCow.3ind4ontrol(RtextboxWR))).*ext); en = ((*ext#ox) (8ridView1.3ooterCow.3ind4ontrol(Rtextbox,R))).*ext; eadd = ((*ext#ox) (8ridView1.3ooterCow.3ind4ontrol(Rtextbox0R))).*ext;
i" ($on.State == 4onne$tionState.4losed) { $on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); Sl4ommand $md = new Sl4ommand();
$md.4ommand*ext = Rinsert into tbempalues(]eno/]en/]eadd/]es)R;
$md.4onne$tion = $on; $md.Parameters.>dd(R]enoR/ Sl2b*7pe.!nt).Value=eno; $md.Parameters.>dd(R]enR/ Sl2b*7pe.Var4&ar/).Value=en; $md.Parameters.>dd(R]eaddR/ Sl2b*7pe.Var4&ar/ ).Value=eadd; $md.Parameters.>dd(R]esR/ Sl2b*7pe.!nt).Value = es;
$md.Exe$uteon\uer7();
// $e can also use adp.insert!ommand cmd$md.2ispose();
8rd#ind();
publi$ !nt+, >uto8en() { Sl4ommand $md = new Sl4ommand();
i" ($on.State==4onne$tionState.4losed) {
$on.4onne$tionString = 4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); $md.4ommand*ext = Rsele$t isull(max(empno)/ ) "rom tbempR;
$md.4onne$tion = $on;
!nt+, r = 4onert.*o!nt+,($md.Exe$uteS$alar())- 1;
- @2 -
-
8/9/2019 ASP Net Notes1
73/173
$md.2ispose(); return r;
prote$ted oid 8ridView1_CowEditing(sender/e)
{ 8ridView1.Edit!ndex = e.ewEdit!ndex; 8rd#ind(); prote$ted oid 8ridView1_Cow2eleting(sender/ e) { !nt+, eno;
// add 9ata?eyame in AridVie$ ;roperty eno = 4onert.*o!nt+,(8ridView1.2ata`e7s 9e.Cow!ndex:9:);
i" ($on.State == 4onne$tionState.4losed) { $on.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext = Rdelete "rom tbemp w&ere empno=]enoR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ Sl2b*7pe.!nt).Value=eno;
$md.Exe$uteon\uer7(); $md.2ispose();
8rd#ind();prote$ted oid 8ridView1_CowBpdating(sender/ e){ !nt+, eno/ es; String en/ eadd; eno = 4onert.*o!nt+,(((Label)(8ridView1.Cows9e.Cow!ndex:.
3ind4ontrol(Rlabel,R))).*ext); es = 4onert.*o!nt+,(((*ext#ox) (8ridView1.Cows9e.Cow!ndex:.
3ind4ontrol(RtextboxR))).*ext); en = ((*ext#ox)(8ridView1.Cows 9e.Cow!ndex:.3ind4ontrol(Rtextbox1R))).*ext; eadd = ((*ext#ox)(8ridView1.Cows9e.Cow!ndex:. 3ind4ontrol(Rtextbox+R))).*ext;
i" ($on.State == 4onne$tionState.4losed) { $on.4onne$tionString = 4on"iguration'anager.
- @; -
-
8/9/2019 ASP Net Notes1
74/173
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext = Rupdate tbemp set ename=]en/ eaddress=]eadd/ esal=]es w&ere empno=]enoR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ Sl2b*7pe.!nt).Value = eno; $md.Parameters.>dd(R]enR/ Sl2b*7pe.Var4&ar/ ).Value = en; $md.Parameters.>dd(R]eaddR/ Sl2b*7pe.Var4&ar/).Value=eadd; $md.Parameters.>dd(R]esR/ Sl2b*7pe.!nt).Value = es;
$md.Exe$uteon\uer7();
$md.2ispose(); 8ridView1.Edit!ndex = 1; 8rd#ind();
prote$ted oid 8ridView1_Cow4an$elingEdit(sender/ e) { 8ridView1.Edit!ndex = 1; 8rd#ind();
- @ -
-
8/9/2019 ASP Net Notes1
75/173
:. TO DI)*LA; DATA IN T
-
8/9/2019 ASP Net Notes1
76/173
G] Page Language=R4UR EnableEventValidation="false"...Grgs e) { i"(KPage.!sPost#a$%) { Sl4onne$tion $on = new Sl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$sR:.4onne$tionString; $on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext = Rsele$t "rom tbboo%R; $md.4onne$tion = $on; Sl2ataCeader dr = $md.Exe$uteCeader(); !nt+, i; "or (i = ; i dr.3ield4ount; i--) { 4&e$%#oxList1.!tems.>dd(dr.8etame(i).*oString()); 33 to get te vaue o tat coumn $e can use etVaue
prote$ted oid #utton1_4li$%(sender/ Eent>rgs e) { String st = RR; !nt+, i; "or (i = ; i 4&e$%#oxList1.!tems.4ount; i--)
- @: -
-
8/9/2019 ASP Net Notes1
77/173
{ i" (4&e$%#oxList1.!tems9i:.Sele$ted == true) { st -= 4&e$%#oxList1.!tems9i:.*ext - R/R;
st = st.Substring(/ st.Lengt& 1); String st1 = Rsele$t R - st - R "rom tbboo%R; Sl2ata>dapter adp=new Sl2ata>dapter(st1/4on"iguration 'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds); 8ridView1.2ataSour$e = ds; 8ridView1.2ata#ind();
- @@ -
-
8/9/2019 ASP Net Notes1
78/173
-
8/9/2019 ASP Net Notes1
79/173
! %arameter name are "ierent rom coumns name
2etailsView1_!temBpdating(sender/ e) { Sl2ataSour$e1.BpdateParameters9RenoR:.2e"aultValue =
e.`e7s9:.*oString();//"nother $ay
??Sl2ataSour$e1.BpdateParameters9RenoR:.2e"aultValue=((*ext#ox) (2etailsView1.Cows9:.4ells91:.4ontrols9:)).*ext;
Sl2ataSour$e1.BpdateParameters9RenR:.2e"aultValue =e.ewValues91:.*oString();
/* $henever $e use update then t$o arrays are ma(e one contaning old values other $ith ne$ values. )n $e refer to array $ith values as e$ValuesC D*/
Sl2ataSour$e1.BpdateParameters9RedR:.2e"aultValue =e.ewValues9,:.*oString();
Sl2ataSour$e1.BpdateParameters9ResR:.2e"aultValue =e.ewValues9+:.*oString();
2etailsView1_!tem!nserting(sender/ e) { Sl2ataSour$e1.!nsertParameters9RenoR:.2e"aultValue=((*ext#ox) (2etailsView1.Cows9:.4ells91:.4ontrols9:)).*ext;
Sl2ataSour$e1.!nsertParameters9RenR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows91:.4ells91:.4ontrols9:)).*ext;
Sl2ataSour$e1.!nsertParameters9RedR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows9,:.4ells91:.4ontrols9:)).*ext;
Sl2ataSour$e1.!nsertParameters9ResR:.2e"aultValue=((*ext#ox) (2etailsView1.Cows9+:.4ells91:.4ontrols9:)).*ext;
2etailsView1_!tem2eleting(sender/ e) { Sl2ataSour$e1.BpdateParameters9RenoR:.2e"aultValue=
e.`e7s9:.*oString();
- @O -
-
8/9/2019 ASP Net Notes1
80/173
DTAIL VIW WIT9 CODIN4
Pace DetaiVei$
A"" (eb 'onig
-
8/9/2019 ASP Net Notes1
81/173
&e$ 'omman"&ame ne$6
Deete'omman"&ame "eete6
7"it!tememetbo7"itDataBin"ingco"e7va8esa96
%"ate 'omman"&ameu%"ate6
'ance 'omman"&ame'ance6
!nsert!temetbo7"itDataBin"ingco"e7va8esa96
Save 'omman"&ame!nsert6
'ance 'omman"&ame 'ance6
o 7m%t+ Data em%ate//5o sho$ table if no data available
!temem%Lin=Buttons
A"" Data to abe 'omman"&amene$6
using S7stem.2ata.Sl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page{ prote$ted oid Page_Load(ob6e$t sender/ Eent>rgs e) { i" (KPage.!sPost#a$%) { 2etail#ind(); priate oid 2etail#ind() { Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t "rom tbempR/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds); 2etailsView1.2ataSour$e = ds; 2etailsView1.2ata#ind(); prote$ted oid 2etailsView1_'ode4&anging(sender/ e) { i" (e.ew'ode == 2etailsView'ode.Edit)
{ 2etailsView1.4&ange'ode(2etailsView'ode.Edit);
// for 8dit)tem5emplate else i" (e.ew'ode == 2etailsView'ode.!nsert) { 2etailsView1.4&ange'ode(2etailsView'ode.!nsert);
// for )nsert)tem5emplate
- N1 -
-
8/9/2019 ASP Net Notes1
82/173
else { 2etailsView1.4&ange'ode(2etailsView'ode.Cead5nl7);
// for )tem5emplate
2etail#ind();
prote$ted oid 2etailsView1_!tem2eleting(sender/ e){ !nt+, eno; eno = 4onert.*o!nt+,(((Label)(2etailsView1. Cows9:.3ind4ontrol(Rlabel1R))).*ext);
Sl4onne$tion $on = new Sl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext = Rdelete "rom tbemp w&ere empno=]enoR;
$md.4onne$tion = $on; $md.Parameters.>dd(R]enoR/ Sl2b*7pe.!nt).Value = eno;
$md.Exe$uteon\uer7(); $md.2ispose();
2etail#ind();prote$ted oid 2etailsView1_!tem!nserting(Sender/ e){ !nt+, eno/ es;
String en/ ed; eno = 4onert.*o!nt+,(((*ext#ox)(2etailsView1. Cows9:.3ind4ontrol(Rtextbox1R))).*ext);
en = ((*ext#ox)(2etailsView1.Cows91:.
3ind4ontrol(Rtextbox+R))).*ext;
ed = ((*ext#ox)(2etailsView1.Cows9,:.
- N2 -
-
8/9/2019 ASP Net Notes1
83/173
3ind4ontrol(RtextboxR))).*ext;
es = 4onert.*o!nt+,(((*ext#ox)(2etailsView1.Cows9+:. 3ind4ontrol(RtextboxQR))).*ext); Sl4onne$tion $on = new Sl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$sR:.4onne$tionString; $on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext = Rinsert into tbemp
alues(]eno/]en/]ed/]es)R; $md.4onne$tion = $on; $md.Parameters.>dd(R]enoR/ Sl2b*7pe.!nt).Value = eno; $md.Parameters.>dd(R]esR/ Sl2b*7pe.!nt).Value = es;$md.Parameters.>dd(R]enR/Sl2b*7pe.Var4&ar/ ).Value=en;
$md.Parameters.>dd(R]edR/Sl2b*7pe.Var4&ar/).Value= ed;
$md.Exe$uteon\uer7(); $md.2ispose();
2etailsView1.4&ange'ode(2etailsView'ode.Cead5nl7); 2etail#ind(); prote$ted oid 2etailsView1_!temBpdating(sender/ e) { !nt+, eno/ es;
String en/ ed; eno = 4onert.*o!nt+,(((Label)(2etailsView1.Cows9:. 3ind4ontrol(Rlabel,R))).*ext); en = ((*ext#ox)(2etailsView1.Cows91:. 3ind4ontrol(Rtextbox,R))).*ext; ed = ((*ext#ox)(2etailsView1.Cows9,:. 3ind4ontrol(Rtextbox0R))).*ext; es = 4onert.*o!nt+,(((*ext#ox)(2etailsView1.Cows9+:. 3ind4ontrol(RtextboxWR))).*ext);
Sl4onne$tion $on = new Sl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString; $on.5pen(); Sl4ommand $md = new Sl4ommand(); $md.4ommand*ext = Rupdate tbemp set ename=]en/
eaddress=]ed/esal=]es w&ere empno=]enoR;
- N; -
-
8/9/2019 ASP Net Notes1
84/173
$md.4onne$tion = $on; $md.Parameters.>dd(R]enoR/Sl2b*7pe.!nt).Value = eno; $md.Parameters.>dd(R]esR/Sl2b*7pe.!nt).Value = es; $md.Parameters.>dd(R]enR/Sl2b*7pe.Var4&ar/).Value=en; $md.Parameters.>dd(R]edR/Sl2b*7pe.Var4&ar/).Value=ed;
$md.Exe$uteon\uer7(); $md.2ispose(); 2etailsView1.4&ange'ode(2etailsView'ode.Cead5nl7); 2etail#ind(); prote$ted oid 2etailsView1_Page!ndex4&anging(sender/ e) { 2etailsView1.Page!ndex = e.ewPage!ndex; 2etail#ind();
:. TO )LCT *RODUCT TO ) T9 DTAIL)
Pace Dro% Do$n List
o coose "ata source SGDataSource1
o 7nabe PostBac=
Pace ri" Vie$
o coose "ata source SGDataSource2
o 7nabe Seect button
Pace Detai Vie$
o coose "ata source SGDataSource;
A"" SGDataSource1
o !n 8&ort(in"9 "atabase cose 8categories9 tabe in $ic seect
8categor+!"9, 8categor+&ame9 coumns
A"" SGDataSource2
o !n 8&ort(in"9 "atabase cose 8Pro"uct9 tabe in $ic seect
8Pro"uct!"9, 8Pro"uct&ame9,9nitPrice9 coumns
o 'ic= on $ere button set
'oumn 'ategor+!"
*%erator Z
Source 'ontro
'ontro!" Dro%Do$nList
o 'ic= on a"" button
A"" SGDataSource;
o !n 8&ort(in"9 "atabase cose 8Pro"uct9 tabe in $ic seect 8T9
coumns
o 'ic= on $ere button set
'oumn Pro"uct!"
- N -
-
8/9/2019 ASP Net Notes1
85/173
*%erator Z
Source 'ontro
'ontro!" ri"Vie$
o 'ic= on a"" button
:. TO )LCT *RODUCT TO *URC9A) AND C9C2 DTAIL
Pace Dro% Do$n List
Pace ri"Vie$1
Pace ri"Vie$2
Pace Lin=Buttons So$ List, A"" items to List, Seect A, Deseect A6
using S7stem.2ata.Sl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page{ prote$ted oid Page_Load(ob6e$t sender/ Eent>rgs e) { i" (KPage.!sPost#a$%) { 2rop2own#ind(); 8rd#ind(); priate oid 2rop2own#ind()
{ t&is.Smartaigation = true; Sl4onne$tion $on = new Sl4onne$tion(); $on.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$sR:.4onne$tionString; $on.5pen(); Sl4ommand $md = new Sl4ommand();
$md.4ommand*ext = RSele$t 4ategor7ame/4ategor7!d "rom
- N -
-
8/9/2019 ASP Net Notes1
86/173
4ategoriesR;
$md.4onne$tion = $on; Sl2ataCeader dr; dr = $md.Exe$uteCeader(); 2rop2ownList1.2ata*ext3ield = R4ategor7ameR; 2rop2ownList1.2ataValue3ield = R4ategor7!dR; 2rop2ownList1.2ataSour$e = dr; 2rop2ownList1.2ata#ind(); dr.4lose(); $md.2ispose(); priate oid 8rd#ind() { String st = RSele$t "rom Produ$ts a/Suppliers b w&ere
a.Supplier!d=b.Supplier!d and 4ategor7!d=R -2rop2ownList1.Sele$tedValue.*oString();
Sl2ata>dapter adp=new Sl2ata>dapter(st/
4on"iguration'anager.4onne$tionStrings9R$sR:. 4onne$tionString);
2ataSet ds = new 2ataSet(); adp.3ill(ds); 8ridView1.2ataSour$e=ds; 8ridView1.2ata#ind(); 2rop2ownList1_Sele$ted!ndex4&anged( sender/ e) { 8rd#ind();
prote$ted oid Lin%#utton0_4li$%(sender/ e) { t&is.Smartaigation = true; !nt+, i; "or (i = ; i 8ridView1.Cows.4ount; i--) { 4&e$%#ox $b = (4&e$%#ox)(8ridView1.Cows9i:. 3ind4ontrol(R$bR)); $b.4&e$%ed = true;
prote$ted oid Lin%#utton+_4li$%(sender/ e) { t&is.Smartaigation = true; !nt+, i; "or (i = ; i 8ridView1.Cows.4ount; i--) { 4&e$%#ox $b = (4&e$%#ox)(8ridView1.Cows9i:. 3ind4ontrol(R$bR));
- N: -
-
8/9/2019 ASP Net Notes1
87/173
$b.4&e$%ed = "alse;
prote$ted oid Lin%#utton,_4li$%(sender/ e)
{ Sl4onne$tion $on1 = new Sl4onne$tion(); $on1.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$s1R:.4onne$tionString;
$on1.5pen();
Sl4ommand $md = new Sl4ommand(); $md.4onne$tion = $on1; "or (!nt+, i = ; i 8ridView1.Cows.4ount; i--) { 4&e$%#ox $b = (4&e$%#ox)(8ridView1.Cows9i:. 3ind4ontrol(R$bR));
i" ($b.4&e$%ed == true) { String pn; !nt+, p; pn =((Label)(8ridView1.Cows9i:. 3ind4ontrol(Rl1R))).*ext; p = 4onert.*o!nt+,(((Label)(8ridView1. Cows9i:.3ind4ontrol(Rl,R))).*ext); $md.4ommand*ext = Rinsert into tbpur$
alues(]pnR-i-R/]pR-i-R)R; $md.Parameters.>dd(R]pnR-i/
Sl2b*7pe.Var4&ar/ ).Value = pn; $md.Parameters.>dd(R]pR-i/Sl2b*7pe.!nt).Value = p;
$md.Exe$uteon\uer7(); $md.2ispose();
prote$ted oid Lin%#utton1_4li$%1(sender/ e) { 8rd#ind,();
priate oid 8rd#ind,() { Sl2ata>dapter adp = new Sl2ata>dapter(Rsele$t $ase w&en(
grouping (Produ$tame)=1) t&en D*otalD else Produ$tame endProdu$tame/ sum(Pri$e) Pri$e "rom tbpur$ group b7 Produ$tame
wit& rollupR/ 4on"iguration'anager.4onne$tionStrings 9R$s1R:.4onne$tionString);
- N@ -
-
8/9/2019 ASP Net Notes1
88/173
2ataSet ds = new 2ataSet(); adp.3ill(ds); 8ridView,.2ataSour$e = ds; 8ridView,.2ata#ind();
prote$ted oid 8ridView,_Cow4ommand(sender/ e) { i" (e.4ommandame == R#u7R) { Sl4onne$tion $on1 = new Sl4onne$tion(); $on1.4onne$tionString = 4on"iguration'anager. 4onne$tionStrings9R$s1R:.4onne$tionString;
$on1.5pen();
Sl4ommand $md = new Sl4ommand(); $md.4onne$tion = $on1; $md.4ommand*ext = Rdelete "rom tbpur$R;
$md.Exe$uteon\uer7();
$md.2ispose();
I 9T6L
st7le t7pe=Rtext?$ssR< .ab${"ontsie@larger;"ontweig&t@bold .x7{2ispla7@none;isibilit7@&idden?st7le