显示分页器行,但在 Gridview 中隐藏页码
Show Pager row, but hide page numbers in Gridview
简单的问题。
我有一个 ASP.net GridView (VS2005),它有页码,但是当每页行数少于最大行数时 (< 10),寻呼机行就会消失。这让我的 gridview 看起来很难看,好像底部少了一行。
我可以强制显示分页器行,但我需要隐藏第 1 页,因为很明显我们在第一页!
<asp:GridView ID="gvFTUNSENT" runat="server"
AutoGenerateColumns="False" CellPadding="4" ForeColor="Black" AllowSorting="True" CssClass="gvCSS" Width="100%"
DataKeyNames="StudentID,StudentUnitID" DataSourceID="sdsFTUNSENT"
GridLines="Vertical" AllowPaging="True" PageSize="10" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
OnPreRender="GridView_PreRender"
OnLoad="GridView_Load"
OnRowDataBound="GridView_RowDataBound" >
<RowStyle Wrap="True" Height="48px" />
<Columns>
...blahblah
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle CssClass="cssPager" BackColor="#6B696B" ForeColor="White" HorizontalAlign="Left" Height="100%" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<EmptyDataTemplate>
<asp:Label ID="lblNDF1" runat="server" Text="NO DATA FOUND" Font-Size="X-Large" Width="500px" style="text-align:center" />
</EmptyDataTemplate>
<EmptyDataRowStyle HorizontalAlign="Center" />
</asp:GridView>
这里我强制显示寻呼机行...
protected void GridView_PreRender(object sender, EventArgs e)
{
GridView gv = (GridView)sender;
//keep showing pager line even if there is only one row of data
GridViewRow gvr = (GridViewRow)gv.BottomPagerRow;
if (gvr != null)
gvr.Visible = true;
}
但我不想在那里看到第 1 页,所以我尝试了这个...
if (e.Row.RowType == DataControlRowType.Pager)
{
//keep showing pager line even if there is only one row of data
GridViewRow gvr = (GridViewRow)e.Row;
if (gvr != null)
{
gvr.Visible = true;
//...but hide page number if there is only one page
if (gv.PageCount == 1)
{
gv.ShowFooter = true;
gv.PagerSettings.Visible = false;
}
}
}
但它实际上隐藏了整个寻呼机行!不!我只想隐藏页码。
ShowFooter,看起来gridview 是一个封闭的盒子。但它仍然很难看。如果我可以保持 Pager 行显示并能够隐藏其中的任何内容,我宁愿不使用它。即.. 保持背景颜色不变。
还有其他想法吗?谢谢
试试
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager && GridView1.PageCount==1 )
{ e.Row.Style.Add("color", "white"); }
}
或者,如果你不想处理颜色,你可以试试这个(但我认为它不太稳健)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager && GridView1.PageCount==1 )
{
var a = e.Row.Controls;
if (a.Count>0 && a[0] is TableCell)
{
var b = a[0].Controls[0].Controls[0] as TableRow;
if (b != null)
{
//This is actually your page 1 text
b.Cells[0].Text = "";
}
}
}
}
简单的问题。
我有一个 ASP.net GridView (VS2005),它有页码,但是当每页行数少于最大行数时 (< 10),寻呼机行就会消失。这让我的 gridview 看起来很难看,好像底部少了一行。
我可以强制显示分页器行,但我需要隐藏第 1 页,因为很明显我们在第一页!
<asp:GridView ID="gvFTUNSENT" runat="server"
AutoGenerateColumns="False" CellPadding="4" ForeColor="Black" AllowSorting="True" CssClass="gvCSS" Width="100%"
DataKeyNames="StudentID,StudentUnitID" DataSourceID="sdsFTUNSENT"
GridLines="Vertical" AllowPaging="True" PageSize="10" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
OnPreRender="GridView_PreRender"
OnLoad="GridView_Load"
OnRowDataBound="GridView_RowDataBound" >
<RowStyle Wrap="True" Height="48px" />
<Columns>
...blahblah
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle CssClass="cssPager" BackColor="#6B696B" ForeColor="White" HorizontalAlign="Left" Height="100%" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<EmptyDataTemplate>
<asp:Label ID="lblNDF1" runat="server" Text="NO DATA FOUND" Font-Size="X-Large" Width="500px" style="text-align:center" />
</EmptyDataTemplate>
<EmptyDataRowStyle HorizontalAlign="Center" />
</asp:GridView>
这里我强制显示寻呼机行...
protected void GridView_PreRender(object sender, EventArgs e)
{
GridView gv = (GridView)sender;
//keep showing pager line even if there is only one row of data
GridViewRow gvr = (GridViewRow)gv.BottomPagerRow;
if (gvr != null)
gvr.Visible = true;
}
但我不想在那里看到第 1 页,所以我尝试了这个...
if (e.Row.RowType == DataControlRowType.Pager)
{
//keep showing pager line even if there is only one row of data
GridViewRow gvr = (GridViewRow)e.Row;
if (gvr != null)
{
gvr.Visible = true;
//...but hide page number if there is only one page
if (gv.PageCount == 1)
{
gv.ShowFooter = true;
gv.PagerSettings.Visible = false;
}
}
}
但它实际上隐藏了整个寻呼机行!不!我只想隐藏页码。
ShowFooter,看起来gridview 是一个封闭的盒子。但它仍然很难看。如果我可以保持 Pager 行显示并能够隐藏其中的任何内容,我宁愿不使用它。即.. 保持背景颜色不变。
还有其他想法吗?谢谢
试试
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager && GridView1.PageCount==1 )
{ e.Row.Style.Add("color", "white"); }
}
或者,如果你不想处理颜色,你可以试试这个(但我认为它不太稳健)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager && GridView1.PageCount==1 )
{
var a = e.Row.Controls;
if (a.Count>0 && a[0] is TableCell)
{
var b = a[0].Controls[0].Controls[0] as TableRow;
if (b != null)
{
//This is actually your page 1 text
b.Cells[0].Text = "";
}
}
}
}