Welcome 微信登录

首页 / 网页编程 / ASP.NET / 如何获取GridView的EmptyDataTemplate中的控件

如何获取GridView的EmptyDataTemplate中的控件2011-08-01 博客园 奇拉网上看了很多用Controls[0].Controls[0]的方法,也很有道理,不过在有数据的情况写可能出出现 Null异常,

这时你可以试试下面的方法,我感觉非常好用。

protected void GridViewSearchResult_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.EmptyDataRow)
{
((Label)(e.Row.FindControl("LabelKeyword"))).Text = Request ["keyword"];
}
}