gridview-paging ソースコード全文
GridView_Paging_CS.sln
Microsoft Visual Studio Solution File, Format Version 12.00# Visual Studio 15VisualStudioVersion = 15.0.28307.421MinimumVisualStudioVersion = 10.0.40219.1Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "GridView_Paging_CS", "GridView_Paging_CS\", "{0D5AF68C-A344-4E54-9EBA-2A60C81DED28}" ProjectSection(WebsiteProperties) = preProject TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.8" Debug.AspNetCompiler.VirtualPath = "/localhost_6559" Debug.AspNetCompiler.PhysicalPath = "GridView_Paging_CS\" Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_6559\" Debug.AspNetCompiler.Updateable = "true" Debug.AspNetCompiler.ForceOverwrite = "true" Debug.AspNetCompiler.FixedNames = "false" Debug.AspNetCompiler.Debug = "True" Release.AspNetCompiler.VirtualPath = "/localhost_6559" Release.AspNetCompiler.PhysicalPath = "GridView_Paging_CS\" Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_6559\" Release.AspNetCompiler.Updateable = "true" Release.AspNetCompiler.ForceOverwrite = "true" Release.AspNetCompiler.FixedNames = "false" Release.AspNetCompiler.Debug = "False" VWDPort = "6559" SlnRelativePath = "GridView_Paging_CS\" DefaultWebSiteLanguage = "Visual C#" EndProjectSectionEndProjectGlobal GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0D5AF68C-A344-4E54-9EBA-2A60C81DED28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0D5AF68C-A344-4E54-9EBA-2A60C81DED28}.Debug|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B16B7345-199E-4D1E-86EC-761C8151C946} EndGlobalSectionEndGlobalGridView_Paging_CS/Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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"> <div> <asp:GridView ID="GridView1" runat="server" Height="402px" Width="655px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" > </asp:GridView> </div> </form></body></html>GridView_Paging_CS/Default.aspx.cs
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { // Session["data"] に DataTable オブジェクトが格納されていない場合、if ブロック内を実行する。 if (Session["data"] == null) { #region DataTable オブジェクトを作成する。 DataColumn[] PrimaryColumn = new DataColumn[1]; DataTable datatable = new DataTable(); PrimaryColumn[0] = datatable.Columns.Add("ID", typeof(string)); datatable.Columns.Add("ProductName", typeof(string)); datatable.Columns.Add("Description", typeof(string)); for (int i = 0; i < 100; i++) { datatable.Rows.Add(i.ToString(), "Product : " + i.ToString(), "Note : " + i.ToString()); } datatable.PrimaryKey = PrimaryColumn; #endregion
// Session["data"] に、DataTable オブジェクトを格納する。 Session["data"] = datatable; }
// Session["data"] から取り出した DataTable を、GridView にバインドする。 this.GridView1.DataSource = Session["data"]; this.GridView1.DataBind(); }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { // GridView に対して、切り替え先のページインデックスを明示する。 this.GridView1.PageIndex = e.NewPageIndex;
// GridView にデータをバインドし直す。 this.GridView1.DataBind(); }}GridView_Paging_CS/Web.config
<?xml version="1.0" encoding="utf-8"?>
<!-- ASP.NET アプリケーションの構成方法の詳細については、 https://go.microsoft.com/fwlink/?LinkId=169433 を参照してください -->
<configuration>
<system.web> <compilation debug="true" targetFramework="4.8"/> <httpRuntime targetFramework="4.8"/> </system.web>
</configuration>GridView_Paging_CS/Web.Debug.config
<?xml version="1.0" encoding="utf-8"?>
<!-- web.config 変換の使用方法の詳細については、https://go.microsoft.com/fwlink/?LinkId=125889 を参照してください -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- 次の例では、"MyDB" という値を持つ "name" 属性が "Match" ロケーターで 見つかった場合にのみ、"SetAttributes" 変換によって "connectionString" の 値が "ReleaseSQLServer" を使用するように変更されます。
<connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> --> <system.web> <compilation xdt:Transform="RemoveAttributes(debug)" /> <!--
次の例では、web.config ファイルの <customErrors> セクション全体が "Replace" 変換によって置き換えられます。 <system.web> ノードには customErrors セクションが 1 つしかないため、 "xdt:Locator" 属性を使用する必要はありません。
<customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> <error statusCode="500" redirect="InternalError.htm"/> </customErrors> > --> </system.web></configuration>