Tải bản đầy đủ - 0 (trang)
Chapter 22. Adding, Editing, and Deleting Records

Chapter 22. Adding, Editing, and Deleting Records

Tải bản đầy đủ - 0trang

2. ClickBrowseandselecttheproducts.mdbdatabaseand

clickNext.



3. IntheColumnslist,selecttheID,ProductName,andPrice

fields.

4. ClickNextandthenFinishtocompletetheconfigurationof

thedatasource.

NowaddanewGridViewcontrol.ChooseGridDataSourcefor

theGridView'sdatasource.EditthecolumnsoftheGridView

andmakesettheIDfield'sVisiblepropertytoFalse,justas

youdidinChapter21.

ThefinalstepinconfiguringtheGridViewcontrolistocheckthe

EnablePaging,EnableSorting,andEnableSelectioncheck

boxesintheCommonGridViewTaskspop-up,asshownin

Figure22.1.

Figure22.1.Enablepaging,sorting,andselection

supportfortheGridViewusingtheCommonGridView

Taskspop-upasshownhere.



IfyouchecktheEnableEditingcheckboxshownpreviouslyin

Figure22.1,theGridViewdisplaysalinktoallowforinline

editingofdata,asshowninFigure22.2.

Figure22.2.TheGridViewsupportsinlineeditingof

databaserecords.

[Viewfullsizeimage]



NocodeisrequiredtoaddeditingcapabilitiestotheGridView

(simplycheckingtheEnableEditingcheckboxissufficient,)but

itmakessensetoallowforeditingintheGridViewitselfonlyif

youaredisplayingallfieldsofthedatabase.Inthiscase,we're

displayingonlyacoupleoffields,sowe'lluseaFormView

controltoeditthedata.

ForadditionaldetailontheGridViewControl,see

"UsingDataControlstoDisplayData,"p.306.



AddingandConfiguringaNewDataSource

JustasyoudidinChapter21,youneedtoaddaseparatedata



sourcecontroltoprovidedataconnectivityforthecontrolused

todisplaydetailsoftheselectedrecord.

AddanewAccessDataSourcecontroltothepageandchange

theIDpropertytoEditDataSource.ClicktheConfigureData

Sourcelinkandconfigureitbyfollowingthesesteps:

1. ClickBrowseandselecttheproducts.mdbdatabase.Click

Next.

2. Selectthe*checkboxintheColumnslist.

3. ClicktheWHEREbuttontoaddanewWHEREclause.

4. SelectIDintheColumndrop-down,=intheOperatordropdown,andControlintheSourcedrop-down.

5. SelectGridView1fromtheControlIDdrop-downandclick

AddtoaddthenewWHEREclause.

6. ClickOK.

7. ClicktheAdvancedbuttonandchecktheGenerateINSERT,

UPDATE,andDELETEStatementscheckbox.

8. ClickOK,andthenclickNextandFinishtocompletethe

configurationofthedatasourcecontrol.

AddanewFormViewcontroltothepageundertheGridView

controlyouaddedearlierandchoosetheEditDataSourcefrom

theChooseDataSourcedrop-downintheCommonFormView

Taskspop-up.



AddingandConfiguringtheFormViewControl



AsImentionedinChapter20,theFormViewcontrolisusedto

displayasingledatabaserecordandallowsfortheediting,

insertion,ordeletingofrecords.AFormViewcontrolissimilar

totheDetailsViewcontrolyouusedinChapter21,buta

FormViewusestemplatestoworkwiththedataandismore

suitableforaddinganinterfaceforadding,editing,anddeleting

data.

Formoredetailonusingtemplates,see"Modifying

Templates,"p.323.



NoticethattheFormViewcontrolyouaddedearlier

automaticallyprovidesalinkforeditingtherecord,deletingthe

record,orforaddinganewrecord,asshowninFigure22.3.

Figure22.3.TheFormViewcontrolprovideslinksfor

editing,deleting,andaddingnewrecordstoyour

database.

[Viewfullsizeimage]



Theinterfaceforeditingthedatabaseisnowcomplete.Let's

moveontocompletingthestepsnecessarytomaketheeditor

fullyfunctional.



Chapter22.Adding,Editing,and

DeletingRecords

INTHISCHAPTER

CreatingtheEditingInterface316

ConfiguringtheFunctionalityoftheEditor319

ModifyingTemplates323

Checkpoint326



CreatingtheEditingInterface

Inthepreviouschapter,yousawhowtocreateaninterfacefor

retrievingrecordsfromadatabase.Thischaptershowsyouhow

tocreateasimilarinterface,butyouwilladdtheabilitiesto

add,edit,anddeleterecordswiththeFormViewcontrol.



AddingandConfiguringaGridViewControl

InChapter13wecreatedanASP.NETrolecalledEditorsand

gavethatrolethecapabilitytobrowsefilesintheeditorfolder

ofthewebapplication.Inthischapteryouaddawebformto

theeditorfolderthatwillprovidetheinterfaceforeditingthe

database.

Right-clickontheeditorfolderandselectAddNewItem.Add

anewwebformnamededitdata.aspxandattachittothe

MasterPage.mastermasterpage.AddanAccessDataSource

controltothepageandchangetheIDpropertyofthe

AccessDataSourcetoGridDataSource.Configurethe

GridDataSourcecontrolbyfollowingthesesteps:

1. ClicktheConfigureDataSourcelinkintheCommon

AccessDataSourceTaskspop-up.



2. ClickBrowseandselecttheproducts.mdbdatabaseand

clickNext.



3. IntheColumnslist,selecttheID,ProductName,andPrice

fields.

4. ClickNextandthenFinishtocompletetheconfigurationof

thedatasource.

NowaddanewGridViewcontrol.ChooseGridDataSourcefor

theGridView'sdatasource.EditthecolumnsoftheGridView

andmakesettheIDfield'sVisiblepropertytoFalse,justas

youdidinChapter21.

ThefinalstepinconfiguringtheGridViewcontrolistocheckthe

EnablePaging,EnableSorting,andEnableSelectioncheck

boxesintheCommonGridViewTaskspop-up,asshownin

Figure22.1.

Figure22.1.Enablepaging,sorting,andselection

supportfortheGridViewusingtheCommonGridView

Taskspop-upasshownhere.



IfyouchecktheEnableEditingcheckboxshownpreviouslyin

Figure22.1,theGridViewdisplaysalinktoallowforinline

editingofdata,asshowninFigure22.2.

Figure22.2.TheGridViewsupportsinlineeditingof

databaserecords.

[Viewfullsizeimage]



NocodeisrequiredtoaddeditingcapabilitiestotheGridView

(simplycheckingtheEnableEditingcheckboxissufficient,)but

itmakessensetoallowforeditingintheGridViewitselfonlyif

youaredisplayingallfieldsofthedatabase.Inthiscase,we're

displayingonlyacoupleoffields,sowe'lluseaFormView

controltoeditthedata.

ForadditionaldetailontheGridViewControl,see

"UsingDataControlstoDisplayData,"p.306.



AddingandConfiguringaNewDataSource

JustasyoudidinChapter21,youneedtoaddaseparatedata



sourcecontroltoprovidedataconnectivityforthecontrolused

todisplaydetailsoftheselectedrecord.

AddanewAccessDataSourcecontroltothepageandchange

theIDpropertytoEditDataSource.ClicktheConfigureData

Sourcelinkandconfigureitbyfollowingthesesteps:

1. ClickBrowseandselecttheproducts.mdbdatabase.Click

Next.

2. Selectthe*checkboxintheColumnslist.

3. ClicktheWHEREbuttontoaddanewWHEREclause.

4. SelectIDintheColumndrop-down,=intheOperatordropdown,andControlintheSourcedrop-down.

5. SelectGridView1fromtheControlIDdrop-downandclick

AddtoaddthenewWHEREclause.

6. ClickOK.

7. ClicktheAdvancedbuttonandchecktheGenerateINSERT,

UPDATE,andDELETEStatementscheckbox.

8. ClickOK,andthenclickNextandFinishtocompletethe

configurationofthedatasourcecontrol.

AddanewFormViewcontroltothepageundertheGridView

controlyouaddedearlierandchoosetheEditDataSourcefrom

theChooseDataSourcedrop-downintheCommonFormView

Taskspop-up.



AddingandConfiguringtheFormViewControl



AsImentionedinChapter20,theFormViewcontrolisusedto

displayasingledatabaserecordandallowsfortheediting,

insertion,ordeletingofrecords.AFormViewcontrolissimilar

totheDetailsViewcontrolyouusedinChapter21,buta

FormViewusestemplatestoworkwiththedataandismore

suitableforaddinganinterfaceforadding,editing,anddeleting

data.

Formoredetailonusingtemplates,see"Modifying

Templates,"p.323.



NoticethattheFormViewcontrolyouaddedearlier

automaticallyprovidesalinkforeditingtherecord,deletingthe

record,orforaddinganewrecord,asshowninFigure22.3.

Figure22.3.TheFormViewcontrolprovideslinksfor

editing,deleting,andaddingnewrecordstoyour

database.

[Viewfullsizeimage]



Theinterfaceforeditingthedatabaseisnowcomplete.Let's

moveontocompletingthestepsnecessarytomaketheeditor

fullyfunctional.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 22. Adding, Editing, and Deleting Records

Tải bản đầy đủ ngay(0 tr)

×