我在GridView中分页怎么变成所有的分页控件都挤到第一个单元格了,百思不得其解,求高手看看
代码如下:protected void gvBlogList_RowCreated(object sender, GridViewRowEventArgs e)
{
int PageSize = this.gvBlogList.PageSize;
int PageIndex = this.gvBlogList.PageIndex;
int PageCount = this.gvBlogList.PageCount;
int RecoderCount = this.gvBlogList.Rows.Count; if (e.Row.RowType == DataControlRowType.Pager)
{
LinkButton Frist = new LinkButton();
LinkButton Prev = new LinkButton();
LinkButton Next = new LinkButton();
LinkButton Last = new LinkButton();
e.Row.Controls.Clear();
TableCell tc = new TableCell();
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("共" + RecoderCount.ToString() + "条记录"));
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("共" + PageCount.ToString() + "页"));
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("当前第" + (PageIndex + 1).ToString() + "页"));
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("每页" + PageSize.ToString() + "条记录"));
tc.Controls.Add(new LiteralControl(" ")); Frist.Text = "首页";
Frist.CommandName = "Page";
Frist.CommandArgument = "First";
Frist.Font.Underline = false; Prev.Text = "上一页";
Prev.CommandName = "Page";
Prev.CommandArgument = "Prev";
Prev.Font.Underline = false; Next.Text = "下一页";
Next.CommandName = "Page";
Next.CommandArgument = "Next";
Next.Font.Underline = false; Last.Text = "尾页";
Last.CommandName = "Page";
Last.CommandArgument = "Last";
Last.Font.Underline = false; if (PageIndex <= 0)
{
Prev.Enabled = false;
Frist.Enabled = false;
}
else
{
Prev.Enabled = true;
Frist.Enabled = true;
}
tc.Controls.Add(Frist);
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(Prev);
tc.Controls.Add(new LiteralControl(" ")); for (int i = 0; i < PageCount; i++)
{
if (i == PageIndex)
{
tc.Controls.Add(new LiteralControl("<span style='color:red;font-weight:bold'>" + (i + 1).ToString() + "</span>")); }
else
{
LinkButton lbBtn = new LinkButton();
lbBtn.Text = (i + 1).ToString();
lbBtn.CommandName = "Page";
lbBtn.CommandArgument = (i + 1).ToString();
lbBtn.Font.Underline = false;
tc.Controls.Add(lbBtn);
}
tc.Controls.Add(new LiteralControl(" "));
}
if (PageIndex >= PageCount - 1)
{
Next.Enabled = false;
Last.Enabled = false;
}
else
{
Next.Enabled = true;
Last.Enabled = true;
}
tc.Controls.Add(Next);
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(Last);
tc.Controls.Add(new LiteralControl(" "));
e.Row.Controls.Clear();
e.Row.Controls.Add(tc);
}
}
html部分是:
<asp:GridView ID="gvBlogList" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="gvBlogList_PageIndexChanging" OnRowCreated="gvBlogList_RowCreated" PageSize="40" HorizontalAlign="Center" OnRowDataBound="gvBlogList_RowDataBound" ShowFooter="true">
<Columns>
<asp:BoundField DataField="BID" HeaderText="编号">
<ItemStyle BackColor="LightCyan" Width="5%" />
<HeaderStyle BackColor="Aqua" Width="5%" />
</asp:BoundField>
<asp:BoundField DataField="BSort" HeaderText="类型">
<ItemStyle Width="10%" />
<HeaderStyle Width="10%" BackColor="Aqua" />
</asp:BoundField>
<asp:TemplateField HeaderText="文章主题">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("BImg") %>'/>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/admin.aspx" Text='<%# Eval("BTopic") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle ForeColor="Red" Width="65%" HorizontalAlign="Left" BackColor="ActiveCaptionText" />
<HeaderStyle Width="65%" BackColor="Aqua" />
</asp:TemplateField>
<asp:BoundField DataField="BaddTime" HeaderText="加入时间">
<ItemStyle Width="15%" />
<HeaderStyle Width="15%" BackColor="Aqua" />
</asp:BoundField>
<asp:BoundField DataField="BAnswerNum" HeaderText="回复数">
<ItemStyle Width="5%" />
<HeaderStyle Width="5%" BackColor="Aqua" />
</asp:BoundField>
</Columns>
<PagerStyle BackColor="#C0FFFF" HorizontalAlign="Right" />
<HeaderStyle ForeColor="#C000C0" />
</asp:GridView>
代码如下:protected void gvBlogList_RowCreated(object sender, GridViewRowEventArgs e)
{
int PageSize = this.gvBlogList.PageSize;
int PageIndex = this.gvBlogList.PageIndex;
int PageCount = this.gvBlogList.PageCount;
int RecoderCount = this.gvBlogList.Rows.Count; if (e.Row.RowType == DataControlRowType.Pager)
{
LinkButton Frist = new LinkButton();
LinkButton Prev = new LinkButton();
LinkButton Next = new LinkButton();
LinkButton Last = new LinkButton();
e.Row.Controls.Clear();
TableCell tc = new TableCell();
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("共" + RecoderCount.ToString() + "条记录"));
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("共" + PageCount.ToString() + "页"));
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("当前第" + (PageIndex + 1).ToString() + "页"));
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(new LiteralControl("每页" + PageSize.ToString() + "条记录"));
tc.Controls.Add(new LiteralControl(" ")); Frist.Text = "首页";
Frist.CommandName = "Page";
Frist.CommandArgument = "First";
Frist.Font.Underline = false; Prev.Text = "上一页";
Prev.CommandName = "Page";
Prev.CommandArgument = "Prev";
Prev.Font.Underline = false; Next.Text = "下一页";
Next.CommandName = "Page";
Next.CommandArgument = "Next";
Next.Font.Underline = false; Last.Text = "尾页";
Last.CommandName = "Page";
Last.CommandArgument = "Last";
Last.Font.Underline = false; if (PageIndex <= 0)
{
Prev.Enabled = false;
Frist.Enabled = false;
}
else
{
Prev.Enabled = true;
Frist.Enabled = true;
}
tc.Controls.Add(Frist);
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(Prev);
tc.Controls.Add(new LiteralControl(" ")); for (int i = 0; i < PageCount; i++)
{
if (i == PageIndex)
{
tc.Controls.Add(new LiteralControl("<span style='color:red;font-weight:bold'>" + (i + 1).ToString() + "</span>")); }
else
{
LinkButton lbBtn = new LinkButton();
lbBtn.Text = (i + 1).ToString();
lbBtn.CommandName = "Page";
lbBtn.CommandArgument = (i + 1).ToString();
lbBtn.Font.Underline = false;
tc.Controls.Add(lbBtn);
}
tc.Controls.Add(new LiteralControl(" "));
}
if (PageIndex >= PageCount - 1)
{
Next.Enabled = false;
Last.Enabled = false;
}
else
{
Next.Enabled = true;
Last.Enabled = true;
}
tc.Controls.Add(Next);
tc.Controls.Add(new LiteralControl(" "));
tc.Controls.Add(Last);
tc.Controls.Add(new LiteralControl(" "));
e.Row.Controls.Clear();
e.Row.Controls.Add(tc);
}
}
html部分是:
<asp:GridView ID="gvBlogList" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="gvBlogList_PageIndexChanging" OnRowCreated="gvBlogList_RowCreated" PageSize="40" HorizontalAlign="Center" OnRowDataBound="gvBlogList_RowDataBound" ShowFooter="true">
<Columns>
<asp:BoundField DataField="BID" HeaderText="编号">
<ItemStyle BackColor="LightCyan" Width="5%" />
<HeaderStyle BackColor="Aqua" Width="5%" />
</asp:BoundField>
<asp:BoundField DataField="BSort" HeaderText="类型">
<ItemStyle Width="10%" />
<HeaderStyle Width="10%" BackColor="Aqua" />
</asp:BoundField>
<asp:TemplateField HeaderText="文章主题">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("BImg") %>'/>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/admin.aspx" Text='<%# Eval("BTopic") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle ForeColor="Red" Width="65%" HorizontalAlign="Left" BackColor="ActiveCaptionText" />
<HeaderStyle Width="65%" BackColor="Aqua" />
</asp:TemplateField>
<asp:BoundField DataField="BaddTime" HeaderText="加入时间">
<ItemStyle Width="15%" />
<HeaderStyle Width="15%" BackColor="Aqua" />
</asp:BoundField>
<asp:BoundField DataField="BAnswerNum" HeaderText="回复数">
<ItemStyle Width="5%" />
<HeaderStyle Width="5%" BackColor="Aqua" />
</asp:BoundField>
</Columns>
<PagerStyle BackColor="#C0FFFF" HorizontalAlign="Right" />
<HeaderStyle ForeColor="#C000C0" />
</asp:GridView>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货