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 > .NET Framework > GridView Ajax and jQuery การสร้าง GridView บน ASP.NET เพื่อเรียกใช้งาน Ajax กับ jQuery




Clound SSD Virtual Server

GridView Ajax and jQuery การสร้าง GridView บน ASP.NET เพื่อเรียกใช้งาน Ajax กับ jQuery

 
  ASP.NET ตัวอย่างการสร้าง GridView และการเรียกใช้งาน Ajax ด้วย jQuery เพื่อเรียกข้อมูลในแต่ละแถวของ GridView แบบง่าย ๆ เป็นภาคต่อของ Ajax jQuery for ASP.NET โดยมีการประยุกต์การใช้งานร่วมกับ GridView โดยหลักการทำงานก็ง่าย ๆ ไม่มีอะไรซับซ้อน คือมีการ BindData ลงใน GridView โดยสร้าง Column ว่า Details และแทรกลิ้งค์ในส่วนของ RowDataBound เพื่อทำการ Call เรียกใช้งานฟังก์ชั่นของ Ajax ในการเรียกข้อมูลมาแสดงในส่วนของข่างล่าง GridView

Basic jQuery for ASP.NET
Go to : Basic jQuery for AJAX in ASP.NET Web Site พื้นฐาน Ajax กับ ASP.NET ด้วย jQuery


เริ่มต้นด้วยการเปิดโปรแกรม Visual Studio

GridView Ajax and jQuery GridView

สร้างโปรเจคที่เป็น ASP.NET Web Site


ตัวอย่างที่ 1 การสร้าง GridView และทำ Link เพื่อสร้าง Popup พร้อมกับส่ง ID ไปยังหน้า Popup เพื่อดึงรายละเอียดมาแสดง


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

<!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 Tutorials</title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script> 
</head>
<body>
    <form id="form1" runat="server">    
    
      <script type="text/javascript">

              function callDetail(CusID) {

                  $.ajax({
                      type: "GET",
                      url: "Details.aspx",
                      cache: false,
                      data: "CusID=" + CusID,
                      success: function(msg) {
                          $("#DivDetail").html(msg);
                      }
                  });
              }

    </script>
     
        <asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False">
	        <Columns>
	        
	        <asp:TemplateField HeaderText="CustomerID">
		        <ItemTemplate>
			        <asp:Label id="lblCustomerID" runat="server"></asp:Label>
		        </ItemTemplate>
	        </asp:TemplateField>

	        <asp:TemplateField HeaderText="Name">
		        <ItemTemplate>
			        <asp:Label id="lblName" runat="server"></asp:Label>
		        </ItemTemplate>
	        </asp:TemplateField>

	        <asp:TemplateField HeaderText="Details">
		        <ItemTemplate>
                    <asp:HyperLink ID="hplDetail" runat="server">Details</asp:HyperLink>
		        </ItemTemplate>
	        </asp:TemplateField>

	        </Columns>
        </asp:GridView>
        <br />
        <div id="DivDetail"></div>
    </form>
</body>
</html>









AjaxJQueryGridView.aspx.vb
Imports System.Data
Imports System.Data.OleDb

Partial Class AjaxJQueryGridView
    Inherits System.Web.UI.Page

    Dim objConn As OleDbConnection
    Dim objCmd As OleDbCommand

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim strConnString As String
        strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
        Server.MapPath("~/App_Data/mydatabase.mdb") & ";"
        objConn = New OleDbConnection(strConnString)
        objConn.Open()

        If Not Page.IsPostBack() Then
            BindData()
        End If

    End Sub

    Protected Sub BindData()

        Dim strSQL As String
        strSQL = "SELECT * FROM customer"

        Dim dtReader As OleDbDataReader
        objCmd = New OleDbCommand(strSQL, objConn)
        dtReader = objCmd.ExecuteReader()

        '*** BindData to GridView ***'
        myGridView.DataSource = dtReader
        myGridView.DataBind()

        dtReader.Close()
        dtReader = Nothing

    End Sub

    Protected Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

            '*** CustomerID ***'
            Dim lblCustomerID As Label = CType(e.Row.FindControl("lblCustomerID"), Label)
            If Not IsNothing(lblCustomerID) Then
                lblCustomerID.Text = e.Row.DataItem("CustomerID")
            End If

            '*** Name ***'
            Dim lblName As Label = CType(e.Row.FindControl("lblName"), Label)
            If Not IsNothing(lblName) Then
                lblName.Text = e.Row.DataItem("Name")
            End If

            '*** Details ***'
            Dim hplDetail As HyperLink = CType(e.Row.FindControl("hplDetail"), HyperLink)
            If Not IsNothing(hplDetail) Then
                hplDetail.NavigateUrl = "JavaScript:void(0);"
                hplDetail.Attributes.Add("OnClick", "JavaScript:callDetail('" & e.Row.DataItem("CustomerID") & "');")
                hplDetail.Attributes.Add("title", e.Row.DataItem("Name"))
            End If
        End If
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        objConn.Close()
        objConn = Nothing
    End Sub

End Class



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

<!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 Tutorials</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <table width="353" border="1">
                <tbody>
                    <tr>
                        <td width="102">
                             <asp:Label id="lblHeadCustomerID" runat="server" text="CustomerID"></asp:Label></td>
                        <td width="235">
                             <asp:Label id="lblCustomerID" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                             <asp:Label id="lblHeadName" runat="server" text="Name"></asp:Label></td>
                        <td>
                             <asp:Label id="lblName" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                             <asp:Label id="lblHeadEmail" runat="server" text="Email"></asp:Label></td>
                        <td>
                             <asp:Label id="lblEmail" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                             <asp:Label id="lblHeadCountryCode" runat="server" text="CountryCode"></asp:Label></td>
                        <td>
                             <asp:Label id="lblCountryCode" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                             <asp:Label id="lblHeadBudget" runat="server" text="Budget"></asp:Label></td>
                        <td>
                             <asp:Label id="lblBudget" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                             <asp:Label id="lblHeadUsed" runat="server" text="Used"></asp:Label></td>
                        <td>
                             <asp:Label id="lblUsed" runat="server"></asp:Label>
                        </td>
                    </tr>
                </tbody>
            </table>    
    </div>
    </form>
</body>
</html>


Details.aspx.vb
Imports System.Data
Imports System.Data.OleDb

Partial Class Details
    Inherits System.Web.UI.Page

    Dim objConn As New OleDbConnection
    Dim objCmd As New OleDbCommand
    Dim dtReader As OleDbDataReader
    Dim strConnString, strSQL As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
        Server.MapPath("~/App_Data/mydatabase.mdb") & ";"
        objConn = New OleDbConnection(strConnString)
        objConn.Open()

        If Not Page.IsPostBack() Then
            ViewData()
        End If
    End Sub

    Protected Sub ViewData()
        '*** DataTable ***'
        Dim dtAdapter As OleDbDataAdapter
        Dim dt As New DataTable
        strSQL = "SELECT * FROM customer WHERE CustomerID = '" & Request.QueryString("CusID") & "' "
        dtAdapter = New OleDbDataAdapter(strSQL, objConn)
        dtAdapter.Fill(dt)

        If dt.Rows.Count > 0 Then
            Me.lblCustomerID.Text = dt.Rows(0)("CustomerID")
            Me.lblName.Text = dt.Rows(0)("Name")
            Me.lblEmail.Text = dt.Rows(0)("Email")
            Me.lblCountryCode.Text = dt.Rows(0)("CountryCode")
            Me.lblBudget.Text = dt.Rows(0)("Budget")
            Me.lblUsed.Text = dt.Rows(0)("Used")
        End If
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        objConn.Close()
        objConn = Nothing
    End Sub
End Class



GridView Ajax and jQuery GridView


คำอธิบาย
บทความนี้เป็นการใช้ jQuery กับ Ajax แบบง่าย ๆ ด้วยการสร้าง function ของ JavaScript ในหน้า Webpage (.aspx) จากนั้นก็ให้ RowDatabound ของ GridView ทำการ Attribute สร้าง Event เพื่อ call ฟังก์ชั่นใน JavaScript อีกที








สำหรับการใช้ Popup กับ jQuery Lightbox สามารถอ่านได้ที่
Go to : ASP.NET GridView Popup and jQuery Lightbox สร้าง Popup บน GridView

บทความอื่น ๆ ASP.NET กับ jQuery
Go to : Basic jQuery for AJAX in ASP.NET Web Site พื้นฐาน Ajax กับ ASP.NET ด้วย jQuery
Go to : Basic ASP.NET jQuery Framework (พื้นฐานง่าย ๆ ด้วย ASP.NET กับ jQuery)
Go to : ASP.NET GridView and Checkbox Select All Row Using jQuery


       
Bookmark.   
       

 

  By : TC Admin
  Score Rating : -
  Create Date : 2011-10-27 16:43:15
  Download : Download  GridView Ajax and jQuery การสร้าง GridView  บน ASP.NET เพื่อเรียกใช้งาน Ajax กับ jQuery (0.75 MB)
     

Clound SSD Virtual Server
-->
Related Links
ติดตั้ง Crystal Report ลงใน Tab Reporting บน Visual Studio 2010 (.NET 4.0)
ติดตั้ง Crystal Report ลงใน Tab Reporting บน Visual Studio 2010 (.NET 4.0)
วิธีการติดตั้ง tools ของ crystal report บน visual studio 2010 (.net framework 4.0) ซึ่งในเวอร์ชั่นนี้จะไม่มีมาพร้อมกับใน pacakge install จะต้องหาดาวน์โหลดมาติดตั้งเอง
Rating :
Update :
2017-03-24 21:31:07 View : 76,241
Basic jQuery for AJAX in ASP.NET Web Site พื้นฐาน Ajax กับ ASP.NET ด้วย jQuery
Basic jQuery for AJAX in ASP.NET Web Site พื้นฐาน Ajax กับ ASP.NET ด้วย jQuery
บทความ jQuery กับการใช้งาน Ajax บน ASP.NET Framework ทำความเข้าใจพื้นฐานการทำงานกับ Ajax ด้วย jQuery กับ ASP.NET แบบง่าย ๆ เบสิก
Rating :
Update :
2017-03-24 21:23:54 View : 21,714
สร้าง Parameter และ Formula Fields บน Crystal Reports (VB.NET,C#)
สร้าง Parameter และ Formula Fields บน Crystal Reports (VB.NET,C#)
บทความ Crystal Report และตัวอย่างการสร้าง Parameters และการส่ง Parameters และการเขียน Formula รับค่าบน Crystal Report
Rating :
Update :
2017-03-24 21:29:30 View : 82,675
ASP.NET GridView Popup and jQuery Lightbox  สร้าง Popup บน GridView
ASP.NET GridView Popup and jQuery Lightbox สร้าง Popup บน GridView
เทคนิคการใช้ GridView ของ ASP.NET กับการเปิด Popup เพื่อแสดงข้อมูลใน Popup และการใช้ Lightbox ของ jQuery ในการแสดงผล
Rating :
Update :
2017-03-24 21:26:25 View : 24,820
การสร้างฟอร์มด้วย DataGridView เบื้องต้นแบบ Step by Step [ VB.NET (Windows App+SQL Server) ]
การสร้างฟอร์มด้วย DataGridView เบื้องต้นแบบ Step by Step [ VB.NET (Windows App+SQL Server) ]
การสร้างฟอร์มด้วย DataGridView เบื้องต้นแบบ Step by Step Development Tool: Visual Studio 2010 Express Database Engine: MS SQL Server 2005 Express
Rating :
Update :
2011-07-24 19:33:14 View : 19,665
Generating Excel Report in .NET Framework
Generating Excel Report in .NET Framework
สร้างไฟล์เอกสาร Excel บน Windows Application และ Console Application ด้วย Framework
Rating :
Update :
2017-03-24 21:16:47 View : 9,726
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 05
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 อัตราราคา คลิกที่นี่

Inline