Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP.NET > ASP.NET AccessDataSource and Control > ASP.NET & AccessDataSource and Repeater



Clound SSD Virtual Server

ASP.NET & AccessDataSource and Repeater

ASP.NET & AccessDataSource and Repeater ในการพัฒนา ASP.NET ด้วย Tool ของ Visual Studio 2005 ขึ้นไปนั้น จะเป็นการสะดวกมากเพราะในการเชื่อมต่อกับฐานข้อมูลนั้น ได้มีการพัฒนา Control ที่มาจัดการ DataSource มากมาย เช่น AccessDataSource หรือ SqlDataSource โดยเพียงลาก Control เหล่านั้นมาวางใน Web Form พร้อมทั้งกำหนดค่า Connection ก็สามารถเชื่อมต่อกับฐานข้อมูลได้เลย ซึ่งลดเวลาการเขียน Code ได้อย่างมาก และไม่ต้องยุ่งยากสำหรับการเขียนคำสั่งในการเชื่อมต่อกับฐานข้อมูล สำหรับตัวอย่างนี้จะเป็นการใช้ AccessDataSource เพื่อดึงข้อมูลจากฐานข้อมูล Microsoft Access (*.mdb) พร้อมกับแสดงข้อมูลโดยใช้ Repeater เข้ามาอ่าน DataSource

ASP.NET & AccessDataSource and Repeater


Framework : 1,2,3,4


ASP.NET & AccessDataSource and Repeater

เริ่มจากการสร้าง Control Repeater


ASP.NET & AccessDataSource and Repeater

เลือก AccessDataSource


ASP.NET & AccessDataSource and Repeater

Browse เลือกไฟล์ Access (*.mdb)


ASP.NET & AccessDataSource and Repeater

เลือกตาราง หรือ Table สำหรับการแสดงผล








ASP.NET & AccessDataSource and Repeater

ทดสอบการ Query เพื่อดูข้อมูล และเลือก Finish


ASP.NET & AccessDataSource and Repeater

ทดสอบการรันเพื่อดูผลลัพธ์

แทรก HeaderTemplate,ItemTemplate และ FooterTemplate

<HeaderTemplate>
	<table border="1">
		<tr>
			<th>CustomerID</th>
			<th>Name</th>
			<th>Email</th>
			<th>CountryCode</th>
			<th>Budget</th>
			<th>Used</th>
		</tr>
</HeaderTemplate>
<ItemTemplate>
	<tr>
		<td align="center"><%#Container.DataItem("CustomerID") %></td>
		<td><%#Container.DataItem("Name") %></td>
		<td><%#Container.DataItem("Email") %></td>
		<td align="center"><%#Container.DataItem("CountryCode") %></td>
		<td align="right"><%#Container.DataItem("Budget") %></td>
		<td align="right"><%#Container.DataItem("Used") %></td>
	</tr>	
	
</ItemTemplate>
<FooterTemplate>
		<!--
		<tr>
			<th>CustomerID</th>
			<th>Name</th>
			<th>Email</th>
			<th>CountryCode</th>
			<th>Budget</th>
			<th>Used</th>
		</tr>
		-->
	</table>
</FooterTemplate>



โค้ดตัวอย่างสำหรับพัฒนาด้วยภาษา VB.NET

Default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ThaiCreate.Com Tutorial</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="AccessDataSource1">
        <HeaderTemplate>
		        <table border="1">
			        <tr>
				        <th>CustomerID</th>
				        <th>Name</th>
				        <th>Email</th>
				        <th>CountryCode</th>
				        <th>Budget</th>
				        <th>Used</th>
			        </tr>
	    </HeaderTemplate>
        <ItemTemplate>
	        <tr>
		        <td align="center"><%#Container.DataItem("CustomerID") %></td>
		        <td><%#Container.DataItem("Name") %></td>
		        <td><%#Container.DataItem("Email") %></td>
		        <td align="center"><%#Container.DataItem("CountryCode") %></td>
		        <td align="right"><%#Container.DataItem("Budget") %></td>
		        <td align="right"><%#Container.DataItem("Used") %></td>
	        </tr>	
    		
        </ItemTemplate>
        <FooterTemplate>
		        <!--
		        <tr>
			        <th>CustomerID</th>
			        <th>Name</th>
			        <th>Email</th>
			        <th>CountryCode</th>
			        <th>Budget</th>
			        <th>Used</th>
		        </tr>
		        -->
	        </table>
        </FooterTemplate>
        </asp:Repeater>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/App_Data/mydatabase.mdb" SelectCommand="SELECT * FROM [customer]">
        </asp:AccessDataSource>
    
    </div>
    </form>
</body>
</html>









   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2010-07-06 06:27:16 / 2017-03-28 22:02:16
  Download : Download  ASP.NET & AccessDataSource and Repeater
 Sponsored Links / Related

 
ASP.NET & AccessDataSource and AdRotator
Rating :

 
ASP.NET & AccessDataSource and BulletedList
Rating :

 
ASP.NET & AccessDataSource and CheckboxList
Rating :

 
ASP.NET & AccessDataSource and DataGrid
Rating :

 
ASP.NET & AccessDataSource and DataList
Rating :

 
ASP.NET & AccessDataSource and DetailsView
Rating :

 
ASP.NET & AccessDataSource and DropDownlist
Rating :

 
ASP.NET & AccessDataSource and FormView
Rating :

 
ASP.NET & AccessDataSource and Listbox
Rating :

 
ASP.NET & AccessDataSource and ListView
Rating :

 
ASP.NET & AccessDataSource and RadioButtonList
Rating :

 
ASP.NET & AccessDataSource and GridView
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่