2017年7月7日 星期五

[研究][C#][ASP.NET][WebForm] GridView 事件執行順序

[研究][C#][ASP.NET][WebForm] GridView 事件執行順序

2017-07-07

Visual Studio 2017

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication6.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" DeleteCommand="DELETE FROM [Table1] WHERE [no] = @no" InsertCommand="INSERT INTO [Table1] ([cname], [addr]) VALUES (@cname, @addr)" SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [cname] = @cname, [addr] = @addr WHERE [no] = @no">
            <DeleteParameters>
                <asp:Parameter Name="no" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="cname" Type="String" />
                <asp:Parameter Name="addr" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="cname" Type="String" />
                <asp:Parameter Name="addr" Type="String" />
                <asp:Parameter Name="no" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" OnPageIndexChanged="GridView1_PageIndexChanged" OnCallingDataMethods="GridView1_CallingDataMethods" OnCreatingModelDataSource="GridView1_CreatingModelDataSource" OnDataBinding="GridView1_DataBinding" OnDataBound="GridView1_DataBound" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnSorted="GridView1_Sorted" OnSorting="GridView1_Sorting" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="no" DataSourceID="SqlDataSource1" OnDisposed="GridView1_Disposed" OnInit="GridView1_Init" OnLoad="GridView1_Load" OnPreRender="GridView1_PreRender" OnRowCreated="GridView1_RowCreated" OnUnload="GridView1_Unload">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
                <asp:BoundField DataField="no" HeaderText="no" InsertVisible="False" ReadOnly="True" SortExpression="no" />
                <asp:BoundField DataField="cname" HeaderText="cname" SortExpression="cname" />
                <asp:BoundField DataField="addr" HeaderText="addr" SortExpression="addr" />
            </Columns>
        </asp:GridView>
        <br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </form>
</body>
</html>


Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication6
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "Page_Load<br />";
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_PageIndexChanged<br />";
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_PageIndexChanging<br />";
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowCancelingEdit<br />";
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowCommand<br />";
        }

        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowDeleted<br />";
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowDeleting<br />";
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowEditing<br />";
        }

        protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowUpdated<br />";
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowUpdating<br />";
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_SelectedIndexChanged<br />";
        }

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_SelectedIndexChanging<br />";
        }

        protected void GridView1_Sorted(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_Sorted<br />";
        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_Sorting<br />";
        }

        protected void GridView1_CallingDataMethods(object sender, CallingDataMethodsEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_CallingDataMethods<br />";
        }

        protected void GridView1_CreatingModelDataSource(object sender, CreatingModelDataSourceEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_CreatingModelDataSource<br />";
        }

        protected void GridView1_DataBinding(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_DataBinding<br />";
        }

        protected void GridView1_DataBound(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_DataBound<br />";
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowDataBound<br />";
        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_RowCreated<br />";
        }

        protected void GridView1_Disposed(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_Disposed<br />";
        }

        protected void GridView1_Init(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_Init<br />";
        }

        protected void GridView1_Load(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_Load<br />";
        }

        protected void GridView1_PreRender(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_PreRender<br />";
        }

        protected void GridView1_Unload(object sender, EventArgs e)
        {
            Label1.Text = Label1.Text + "GridView1_Unload<br />";
        }
    }
}

執行後

GridView1_Init
Page_Load
GridView1_Load
GridView1_DataBinding
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_DataBound
GridView1_PreRender
********************************************************************************
按下「編輯」
Page_Load
GridView1_Load
GridView1_RowCommand
GridView1_RowEditing
GridView1_DataBinding
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_DataBound
GridView1_PreRender
********************************************************************************
按下「更新」(按下「編輯」後)
Page_Load
GridView1_Load
GridView1_RowCommand
GridView1_RowUpdating
GridView1_RowUpdated
GridView1_DataBinding
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_DataBound
GridView1_PreRender
********************************************************************************
按下「取消」(按下「編輯」後)
Page_Load
GridView1_Load
GridView1_RowCommand
GridView1_RowCancelingEdit
GridView1_DataBinding
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_DataBound
GridView1_PreRender
********************************************************************************點選欄位標題進行排序
Page_Load
GridView1_Load
GridView1_RowCommand
GridView1_Sorting
GridView1_Sorted
GridView1_DataBinding
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_DataBound
GridView1_PreRender
********************************************************************************
按下「選取」
Page_Load
GridView1_Load
GridView1_RowCommand
GridView1_SelectedIndexChanging
GridView1_SelectedIndexChanged
GridView1_PreRender
********************************************************************************
按下「刪除」
Page_Load
GridView1_Load
GridView1_RowCommand
GridView1_RowDeleting
GridView1_RowDeleted
GridView1_DataBinding
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_RowCreated
GridView1_RowDataBound
GridView1_DataBound
GridView1_PreRender

(完)

沒有留言:

張貼留言