在GridView的Command事件中可以用下面的语句来找到:

GridView中控件的事件中,可以用下面的语句来找到:


在Page_Load怎么找到,还没有想到?
下面资料转自:http://www.itzhe.cn/html/web/ASP.NET/20071127/22928_2.html
用 gridview 实现插入功能时遇到的问题
// create a new header row
GridViewRow headerRow = base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
this.InitializeRow(headerRow, fields);
// add the header row to the table
table.Rows.Add(headerRow);
}
// create the empty row
GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
TableCell cell = new TableCell(); itzhe.cn
cell.ColumnSpan = fields.Length;
cell.Width = Unit.Percentage(100);
// respect the precedence order if both EmptyDataTemplate
// and EmptyDataText are both supplied
if (this.EmptyDataTemplate != null)
{
this.EmptyDataTemplate.InstantiateIn(cell);
}
else if (!string.IsNullOrEmpty(this.EmptyDataText))
{
cell.Controls.Add(new LiteralControl(EmptyDataText));
IT 者
}
emptyRow.Cells.Add(cell);
table.Rows.Add(emptyRow);
//if (this.ShowFooterWhenEmpty)
//{
// create footer row
GridViewRow footerRow = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
this.InitializeRow(footerRow, fields);
// add the footer to the table
table.Rows.Add(footerRow);
//}
this.Controls.Clear();
www.itzhe.cn
this.Controls.Add(table);
this.ShowFooter = true;
}
return rows;
}
}
GridViewRow headerRow = base.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
this.InitializeRow(headerRow, fields);
// add the header row to the table
table.Rows.Add(headerRow);
}
// create the empty row
GridViewRow emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
TableCell cell = new TableCell(); itzhe.cn
cell.ColumnSpan = fields.Length;
cell.Width = Unit.Percentage(100);
// respect the precedence order if both EmptyDataTemplate
// and EmptyDataText are both supplied

if (this.EmptyDataTemplate != null)
{
this.EmptyDataTemplate.InstantiateIn(cell);
}
else if (!string.IsNullOrEmpty(this.EmptyDataText))
{
cell.Controls.Add(new LiteralControl(EmptyDataText));
IT 者
}
emptyRow.Cells.Add(cell);
table.Rows.Add(emptyRow);
//if (this.ShowFooterWhenEmpty)
//{
// create footer row
GridViewRow footerRow = base.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
this.InitializeRow(footerRow, fields);
// add the footer to the table
table.Rows.Add(footerRow);
//}
this.Controls.Clear();
www.itzhe.cn
this.Controls.Add(table);
this.ShowFooter = true;
}
return rows;
}
}
功能实现了,没有数据的时候header和footer都能显示,我把插入数据要输入的项目都放在footer里面,所以没有数据的时候,始终会显示一条插入纪录,但当我提交以后,gridView.FooterRow.FindControl( "tb_foot_name ") 返回空值。但假如表格里边本身有数据的话 gridView.FooterRow.FindControl( "tb_foot_name ")能够返回对象,区别是:
但没有数据时,footer是我自己创建的,有数据时footer是系统创建的。
请问大家,有何良策
谢谢
本篇文章来源于 www.itzhe.cn 原文链接:http://www.itzhe.cn/html/web/ASP.NET/20071127/22928_2.html