如何获取GridView的EmptyDataTemplate中的控件

如何查找GridView的EmptyDataTemplate中的控件

网上看了很多用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"];
        }
    }
原文地址:https://www.cnblogs.com/keyrratuff/p/1438466.html