当前位置:编程学习 > asp >>

DataGrid使用技巧小总结

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">
补充:asp教程,数据库相关
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,