求助gridview重新格式:第1页 [2][3][4]....代码
如题,使用gridveiw自带的分页,原来的效果是1 2 3 4 5 6 7,能否改为
第1页 [2][3][4]....,我把2003里使用的方式用在2005,但会出错。
if (e.Row.RowType == DataControlRowType.Pager)
{
TableCell pager = (TableCell)e.Row.Controls[0];
for (int i = 0; i < pager.Controls.Count; i += 2)
{
Object o = pager.Controls[i];
if (o is LinkButton)
{
LinkButton h = (LinkButton)o;
h.Text = "[ " + h.Text + "] ";
}
else
{
Label l = (Label)o;
l.Text = "第 " + l.Text + "页 ";
}
}
}
谁有改好的?谢谢!
------解决方案--------------------protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
TableRow row = e.Row.Controls[0].Controls[0].Controls[0] as TableRow;
foreach (TableCell cell in row.Cells)
{
Control lb = cell.Controls[0];
if (lb is Label)
{
((Label)lb).ForeColor = System.Drawing.Color.Red;
((Label)lb).Font.Size = new FontUnit( "20px ");
}
else if (lb is LinkButton)
{
((LinkButton)lb).Text = "[ " + ((LinkButton)lb).Text + "] ";
}
}
}