SlideShare ist ein Scribd-Unternehmen logo
1 von 10
第九章 DataBinding觀念與
SqlDataSource精靈的限制
E-Mail -- mis2000lab@yahoo.com.tw
網站 http://www.dotblogs.com.tw/mis2000lab/
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
1
MIS2000 Lab.簡介
• 工作室成員包含:大學教授、業界技術經理、微軟MVP獎得主。
• 想要親自上課,請參考:
http://www.dotblogs.com.tw/mis2000lab/archive/2011/06/24/29807.aspx
• Blog(範例與新技術):http://www.dotblogs.com.tw/mis2000lab/
• FaceBook社群:https://www.facebook.com/mis2000lab
• YouTube教學影片(不定期更新):https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA
• G+社群:https://plus.google.com/u/0/100202398389206570368/posts
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
2
MIS2000 Lab.當面授課,機會難得!
• ASP.Net (Web Form) 上課內容&報名,請恰:
• http://www.dotblogs.com.tw/mis2000lab/archive/2011/06/24/29807.aspx
• 自2011年初開課以來,全省已經有650人次以上參與本課程!
• E-Mail -- mis2000lab@yahoo.com.tw
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
3
9-1 資料繫結,DataBinding的觀念
• 大型控制項(例如GridView、DetailsView等,又稱為資料繫結控
制項)是「呈現」資料到畫面上的UI(使用者介面),是一種給
使用者用的操作介面。
• DataSource控制項(資料來源控制項,如SqlDataSource)才是真
正連結資料庫,執行資料「撈出(查詢)、回寫」動作。
• 之前章節學習到的範例就是利用上述兩者(雙劍合璧)的威力,
完成了許多Master-Details主表明細功能。
• 兩者的結合就是「資料繫結(DataBinding)」。
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
4
• 下面兩張圖片說明了DetailsView + SqlDataSource兩種控制項是如
何結合在一起?綁定在一起?
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
5
9-2 SqlDataSource的缺失(Bug)
• 範例1_DropDownList_Error.aspx是上一章做的範例,只要
DetailsView可新增、刪除、編輯(更新),就會發覺大缺失。
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
6
9-2 SqlDataSource的缺失(Bug)
• 範例1_DropDownList_Error.aspx是上一章做的範例,只要
DetailsView可新增、刪除、編輯(更新),就會發覺大缺失。
• 請直接觀賞影片與說明:
• https://www.youtube.com/watch?v=P7AKhH-9YrE&feature=youtu.be
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
7
9-3 自己寫程式來做DataBinding
• 瞭解上一個範例(1_DropDownList_Error.aspx)的缺失以後,我們
依照「流程」來解說並稍做修改。
• 第一,點選 DropDownList選一篇文章。
• 第二,下方的DetailsView出現這篇文章的詳細內容。然後去編
輯(修改)這篇文章的標題。
• 第三,修改”以後”(重點!!),上方的DropDownList如果
可以”重新”從資料庫取得最新的資料,就可以避開上一個範
例的缺失!
DetailsView的 ItemUpdated事件裡面,寫這段程式:
DropDownList1.DataSourceID = “SqlDataSource1”
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
8
9-4 Case Study─
我的GridView有「新增」功能
• 範例 Default_book_4_GridView_Add.aspx 執行結果。
• GridView控制項竟然有一個新增資料的按鈕?還可以呼叫出
DetailsView控制項?
• 本範例較為進階,
老師請依實際狀況決定
是否教學?
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
9
• GridView並沒有新增(Insert)的樣板,所以我們必
須放在「EmptyDataTemplate」樣板裡面。
• 第一、負責新增資料的DetailsView(請將它預設為「新增」模
式),並將它塞到GridView的「EmptyDataTemplate」樣板裡面。
• 第二、設計一個Button按鈕,務必設定CommandName(請自
行命名)。當使用者一按下這個按鈕,就要開啟「GridView的
EmptyDataTemplate樣板」。
當使用者一按下這個按鈕,就要開啟「GridView的
EmptyDataTemplate樣板」,這部份需要動些手腳,請看下一步驟。
• 第三、當SqlDataSource資料來源控制項“找不到任何資料(null
或Nothing)”時,就會啟動GridView的EmptyDataTemplate樣板!
ASP.NET學習教材(松崗),作者:MIS2000 Lab.,網站
http://www.dotblogs.com.tw/mis2000lab/
10

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

09 DataBinding & SqlDataSource的小錯誤 (ASP.NET)