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,025

HOME > ASP.NET > ASP.NET DataGrid Control > ASP.NET DataGrid Control



Clound SSD Virtual Server

ASP.NET DataGrid Control

ASP.NET DataGrid Control เป็นคอนโทรลที่ใช้ในการจัดการข้อมูลที่เป็นลักษณะ คอลัมบ์และแถว (Column,Rows) โดยสามารถทำการกำหนดในส่วนของการ Add,Edit หรือ Delete ได้ โดยการใช้เงื่อนไขของ TemplateColumn ในการแสดงโหมดต่าง ๆ


ASP.NET DataGrid Control


ASP.NET DataGrid Control

Framework : 1,2,3,4

Syntax

<asp:DataGrid id="[Name]" runat="server"></asp:DataGrid>


TemplateColumn

<HeaderTemplate>
// ส่วนหัว
</HeaderTemplate>

<ItemTemplate>
// ส่วนของการแสดงผลโหมดปกติ
</ItemTemplate>

<EditItemTemplate>
// ส่วนของการแสดงการแก้ไข
</EditItemTemplate>

<FooterTemplate>
// ส่วนล่างหรือ Footer
</FooterTemplate>




Event

Event เป็นตัวควบคุมเหตุการณ์ต่าง ๆ ของ DataGrid ซึ่งในบทเรียนนี้ผมได้ยกตัวอย่างการใช้ Event ต่าง ๆ หลายตัว และ Event ที่ใช้อยู่ประจำเช่น

- ItemCreated เมื่อ DataGrid ทำการ Created หรือเสร็จสิ้น
- ItemDataBound เมื่อ DataGrid มีการ Bound ข้อมูลในแต่ล่ะ Rows
- EditCommand เมื่อ DataGrid มีการคลิกโหมดแก้ไข
- CancelCommand เมื่อ DataGrid มีการคลิกยกเลิกการแก้ไข
- UpdateCommand เมื่อ DataGrid มีการคลิก Update
- SelectedIndexChanged เมื่อ DataGrid มีการคลิก Event เปลี่ยนหน้า
- SortCommand เมื่อ DataGrid มีการคลิกจัดเรียง
- ItemCommand เมื่อ DataGrid มีการคลิกทำคำสั่งต่าง ๆ


Handles

การกำหนด Event Handles สามารถกำหนดได้ 2 รูปแบบครับ คือกำหนดในส่วนของ Tag DataGrid หรือ กำหนดในส่วนของ Event Handles ของ Sub หรือ Function

1. กำหนดในส่วนของ Tag DataGrid

<asp:DataGrid id="myDataGrid" runat="server" onItemDataBound="myDataGrid_ItemDataBound"></asp:DataGrid>

<script runat="server">
Sub myDataGrid_ItemDataBound(sender As Object, e As DataGridItemEventArgs)

End Sub
</script>



2. กำหนดในส่วนของ Sub หรือ Function

<asp:DataGrid id="myDataGrid" runat="server></asp:DataGrid>

Private Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles myDataGrid.ItemDataBound

End Sub











Declarative Syntax
<asp:DataGrid
    AccessKey="string"
    AllowCustomPaging="True|False"
    AllowPaging="True|False"
    AllowSorting="True|False"
    AutoGenerateColumns="True|False"
    BackColor="color name|#dddddd"
    BackImageUrl="uri"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    Caption="string"
    CaptionAlign="NotSet|Top|Bottom|Left|Right"
    CellPadding="integer"
    CellSpacing="integer"
    CssClass="string"
    DataKeyField="string"
    DataMember="string"
    DataSource="string"
    DataSourceID="string"
    EditItemIndex="integer"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    GridLines="None|Horizontal|Vertical|Both"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnCancelCommand="CancelCommand event handler"
    OnDataBinding="DataBinding event handler"
    OnDeleteCommand="DeleteCommand event handler"
    OnDisposed="Disposed event handler"
    OnEditCommand="EditCommand event handler"
    OnInit="Init event handler"
    OnItemCommand="ItemCommand event handler"
    OnItemCreated="ItemCreated event handler"
    OnItemDataBound="ItemDataBound event handler"
    OnLoad="Load event handler"
    OnPageIndexChanged="PageIndexChanged event handler"
    OnPreRender="PreRender event handler"
    OnSelectedIndexChanged="SelectedIndexChanged event handler"
    OnSortCommand="SortCommand event handler"
    OnUnload="Unload event handler"
    OnUpdateCommand="UpdateCommand event handler"
    PageSize="integer"
    runat="server"
    SelectedIndex="integer"
    ShowFooter="True|False"
    ShowHeader="True|False"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    UseAccessibleHeader="True|False"
    Visible="True|False"
    Width="size"
>
        <AlternatingItemStyle />
        <Columns>
                <asp:BoundColumn
                    DataField="string"
                    DataFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    ReadOnly="True|False"
                    SortExpression="string"
                    Visible="True|False"
>
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:BoundColumn>
                <asp:ButtonColumn
                    ButtonType="LinkButton|PushButton"
                    CausesValidation="True|False"
                    CommandName="string"
                    DataTextField="string"
                    DataTextFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    SortExpression="string"
                    Text="string"
                    ValidationGroup="string"
                    Visible="True|False"
>
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:ButtonColumn>
                <asp:EditCommandColumn
                    ButtonType="LinkButton|PushButton"
                    CancelText="string"
                    CausesValidation="True|False"
                    EditText="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    SortExpression="string"
                    UpdateText="string"
                    ValidationGroup="string"
                    Visible="True|False"
>
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:EditCommandColumn>
                <asp:HyperLinkColumn
                    DataNavigateUrlField="string"
                    DataNavigateUrlFormatString="string"
                    DataTextField="string"
                    DataTextFormatString="string"
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    NavigateUrl="uri"
                    SortExpression="string"
                    Target="string|_blank|_parent|_search|_self|_top"
                    Text="string"
                    Visible="True|False"
>
                        <FooterStyle />
                        <HeaderStyle />
                        <ItemStyle />
                </asp:HyperLinkColumn>
                <asp:TemplateColumn
                    FooterText="string"
                    HeaderImageUrl="uri"
                    HeaderText="string"
                    SortExpression="string"
                    Visible="True|False"
>
                            <FooterStyle />
                            <HeaderStyle />
                            <ItemStyle />
                        <EditItemTemplate>
                            <!-- child controls -->
                        </EditItemTemplate>
                        <FooterTemplate>
                            <!-- child controls -->
                        </FooterTemplate>
                        <HeaderTemplate>
                            <!-- child controls -->
                        </HeaderTemplate>
                        <ItemTemplate>
                            <!-- child controls -->
                        </ItemTemplate>
                </asp:TemplateColumn>
        </Columns>
        <EditItemStyle />
        <FooterStyle />
        <HeaderStyle />
        <ItemStyle />
        <PagerStyle
            BackColor="color name|#dddddd"
            BorderColor="color name|#dddddd"
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                Groove|Ridge|Inset|Outset"
            BorderWidth="size"
            CssClass="string"
            Font-Bold="True|False"
            Font-Italic="True|False"
            Font-Names="string"
            Font-Overline="True|False"
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
                Medium|Large|X-Large|XX-Large"
            Font-Strikeout="True|False"
            Font-Underline="True|False"
            ForeColor="color name|#dddddd"
            Height="size"
            HorizontalAlign="NotSet|Left|Center|Right|Justify"
            Mode="NextPrev|NumericPages"
            NextPageText="string"
            OnDisposed="Disposed event handler"
            PageButtonCount="integer"
            Position="Bottom|Top|TopAndBottom"
            PrevPageText="string"
            VerticalAlign="NotSet|Top|Middle|Bottom"
            Visible="True|False"
            Width="size"
            Wrap="True|False"
        />
        <SelectedItemStyle />
</asp:DataGrid>


สำหรับการใช้งาน DataGrid ในรูปแบบต่าง ๆ สามารถศึกษาได้จากหัวข้อถัดไปครับ








   
Share


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-27 07:22:32 / 2017-03-28 21:05:08
  Download : No files
 Sponsored Links / Related

 
ASP.NET DataGrid Control - DataBind
Rating :

 
ASP.NET DataGrid Control - AlternateRows
Rating :

 
ASP.NET DataGrid Control - TemplateColumn
Rating :

 
ASP.NET DataGrid Control - DataBound
Rating :

 
ASP.NET DataGrid Control - AllowSorting
Rating :

 
ASP.NET DataGrid Control - AllowPaging
Rating :

 
ASP.NET DataGrid Control - AllowSorting and AllowPaging
Rating :

 
ASP.NET DataGrid Control - FindControl
Rating :

 
ASP.NET DataGrid Control - DataSet,DataTable,TableRows
Rating :

 
ASP.NET DataGrid Control - ItemCommand
Rating :

 
ASP.NET DataGrid Control - XML
Rating :

 
ASP.NET DataGrid Control - AccessDataSource
Rating :

 
ASP.NET DataGrid Control - VS .NET 2003 (FX 1.1)
Rating :

 
ASP.NET DataGrid Control - VS 2005,2008,2010 (FX 2.0,3.5,4.0)
Rating :

 
ASP.NET DataGrid Control - Microsoft Access (.mdb) - System.Data.OleDb
Rating :

 
ASP.NET DataGrid Control - SQL Server 2000,2005,2008 - System.Data.SqlClient
Rating :

 
ASP.NET DataGrid Control - MySQL Database - MySql.Data.MySqlClient
Rating :

 
ASP.NET DataGrid Control - Oracle Database - System.Data.OracleClient
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 01
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 อัตราราคา คลิกที่นี่