ページャーをテンプレートに変換しますが、ページ インデックスを表示および管理するための独自のロジックを作成する必要があります。
サンプルコードはこちら
<PagerTemplate>
<asp:Panel ID="gvpanel" runat="server">
<table cellpadding="3" cellspacing="3" class="style4">
<tr>
<td width="20%">
<asp:Label ID="Label4" runat="server" CssClass="lb" Text="Page "></asp:Label>
<asp:DropDownList ID="ddpage" runat="server" AutoPostBack="True" CssClass="txt"
onselectedindexchanged="ddpage_SelectedIndexChanged">
</asp:DropDownList>
<asp:Label ID="Label5" runat="server" CssClass="lb" Text="of "></asp:Label>
<asp:Label ID="lbltot" runat="server" CssClass="lb" Text="0"></asp:Label>
</td>
<td width="60%">
<table class="style1">
<tr>
<td width="15%">
<asp:LinkButton ID="lbp10" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lbp10_Click">Previous 10</asp:LinkButton>
</td>
<td width="15%">
<asp:LinkButton ID="lbp" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lbp_Click">Previous</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb1" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">1 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb2" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">2 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb3" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">3 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb4" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">4 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb5" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">5 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb6" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">6 </asp:LinkButton>
</td>
<td >
<asp:LinkButton ID="lb7" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">7 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb8" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">8 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb9" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">9 </asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lb10" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lb1_Click">10</asp:LinkButton>
</td>
<td width="15%">
<asp:LinkButton ID="lbn" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lbn_Click">Next</asp:LinkButton>
</td>
<td width="15%">
<asp:LinkButton ID="lbn10" runat="server" CssClass="smalllinkbuttonf"
Enabled="False" onclick="lbn10_Click">Next 10</asp:LinkButton>
</td>
</tr>
</table>
</td>
<td width="20%">
</td>
</tr>
</table>
</asp:Panel>
</PagerTemplate>
ここにc#コードがあります
protected void lbp10_Click(object sender, EventArgs e)
{
GridView1.PageIndex = (GridView1.PageIndex - 10);
bind();
}
protected void lbp_Click(object sender, EventArgs e)
{
GridView1.PageIndex = (GridView1.PageIndex - 1);
bind();
}
protected void lbn_Click(object sender, EventArgs e)
{
GridView1.PageIndex = (GridView1.PageIndex + 1);
bind();
}
protected void lbn10_Click(object sender, EventArgs e)
{
GridView1.PageIndex = (GridView1.PageIndex + 10);
bind();
}
protected void lb1_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
GridView1.PageIndex = (int.Parse(lb.Text) - 1);
bind();
}
フッターを作成するためのコード
void addfooter(int rcount)
{
if (GridView1.BottomPagerRow == null)
{
return;
}
Panel p = (Panel)GridView1.BottomPagerRow.FindControl("gvpanel");
DropDownList dd = (DropDownList)p.FindControl("ddpage");
for (int i = 0; i < rcount; i++)
{
ListItem li = new ListItem();
li.Text = (i + 1).ToString();
li.Value = (i + 1).ToString();
dd.Items.Add(li);
}
Label lbltot = (Label)p.FindControl("lbltot");
lbltot.Text = GridView1.PageCount.ToString();
dd.SelectedIndex = GridView1.PageIndex;
LinkButton lbp10 = (LinkButton)p.FindControl("lbp10");
lbp10.Enabled = false;
lbp10.CssClass = "smalllinkbuttonfd";
LinkButton lbp = (LinkButton)p.FindControl("lbp");
lbp.Enabled = false;
lbp.CssClass = "smalllinkbuttonfd";
LinkButton lbn10 = (LinkButton)p.FindControl("lbn10");
lbn10.Enabled = false;
LinkButton lbn = (LinkButton)p.FindControl("lbn");
lbn.CssClass = "smalllinkbuttonfd";
lbn.Enabled = false;
lbn10.CssClass = "smalllinkbuttonfd";
int cpage = GridView1.PageIndex + 1;
int totpage = GridView1.PageCount;
if (cpage > 10)
{
lbp10.Enabled = true;
lbp10.CssClass = "smalllinkbuttonf";
}
if (cpage > 1)
{
lbp.Enabled = true;
lbp.CssClass = "smalllinkbuttonf";
}
if (cpage < totpage)
{
lbn.Enabled = true;
lbn.CssClass = "smalllinkbuttonf";
}
if (cpage + 10 < totpage)
{
lbn10.Enabled = true;
lbn10.CssClass = "smalllinkbuttonf";
}
for (int i = 1; i < 11; i++)
{
LinkButton lb = (LinkButton)p.FindControl("lb" + i.ToString());
lb.Enabled = false;
lb.CssClass = "smalllinkbuttonfd";
}
int tstart = cpage / 10;
int lcount = tstart + 10;
//int scount = tstart - 10;
int cnt = 1;
for (int i = (tstart * 10); i <= ((tstart * 10) + 10); i++)
{
if (cnt > 10)
{
return;
} if ((i + 1) > totpage)
{
LinkButton lb = (LinkButton)p.FindControl("lb" + cnt.ToString());
lb.Enabled = false;
lb.Text = (i + 1).ToString();
lb.CssClass = "smalllinkbuttonfd";
cnt++;
}
else
{
if ((i + 1) == cpage)
{
LinkButton lb = (LinkButton)p.FindControl("lb" + cnt.ToString());
lb.Enabled = false;
lb.Text = (i + 1).ToString();
lb.CssClass = "smalllinkbuttonfd";
cnt++;
}
else
{
LinkButton lb = (LinkButton)p.FindControl("lb" + cnt.ToString());
lb.Enabled = true;
lb.Text = (i + 1).ToString();
lb.CssClass = "smalllinkbuttonf";
cnt++;
}
}
}
}
Onlink ボタンに onclientclick を追加できるようになりました