日期:2012-09-01  浏览次数:20902 次

DataGrid 自定义分页导航


效果:


让DataGrid自己的分页实现这样的效果
[1][2][3][4][5][6]



private void grid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Pager)
{
foreach (Control c in e.Item.Cells[0].Controls)
{
if (c is Label) //当前页数
{
Label lblpage=(Label)c;
// lblpage.ForeColor= System.Drawing.ColorTranslator.FromHtml("#e78a29"); //#e78a29 ,#FF0000
// lblpage.Font.Bold=true;
lblpage.Text="[<font color=#e78a29><b>"+lblpage.Text+"</b></font>]";
//((Label)c).ForeColor = System.Drawing.Color.Green;
// break;
}
if(c is LinkButton) //链接的其他页数
{
LinkButton linkButton = (LinkButton)c;
linkButton.Text = "[" + linkButton.Text+"]";
}
}
}
}





DataGrid等控件中的自动编号:

添加一个模版列:

<asp:TemplateColumn HeaderText="No.">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label runat="server" Text='<%# dgCustomize.CurrentPageIndex*dgCustomize.PageSize+dgCustomize.Items.Count+1 %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>





DataGrid中创建复杂表头

方法一:用table实现

<form id="Form1" method="post" runat="server">
<TABLE id="Table1" runat="server" cellSpacing="1" cellPadding="2" width="580" border="1"
bgcolor="#cc6633" bordercolor="#cc9966" style="FONT-SIZE:9pt;BORDER-BOTTOM:0px">
<TR align="center">
<TD colspan="2" width="380" style="HEIGHT: 21px"></TD>
<TD width="200" colspan="2" style="HEIGHT: 21px"></TD>
</TR>
<TR align="center">
<TD width="200" bgcolor="#66cc99"><FONT face="宋体"></FONT></TD>
<TD width="180" bgcolor="white"><FONT face="宋体"></FONT></TD>
<TD width="160" bgcolor="#99cccc"></TD>
<TD width="40" bgcolor="#009999"></TD>
</TR>
</TABLE>
<asp:DataGrid id="DataGrid1" width="580px" AlternatingItemStyle-BackColor="#6699ff" CellPadding="2"
CellSpacing="1" BorderWidth="1" BorderColor="#cc9966" Font-Size="9pt" runat="server" ShowHeader="False"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Title">
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="CreateDate">
<ItemStyle Width="180px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="pid">
<ItemStyle Width="160px"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="HitCount">
<ItemStyle Width="40px"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>

窗体顶端











窗体底端
<