1

我正在使用 EmptyDataTemplate 在网格中输入新数据,而没有现有数据,但我无法在 EmptyDateTemplate 中找到我的控件

protected void gvNavigationDtls_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("EInsert"))
        {
            GridViewRow emptyrow = gvNavigationDtls.Controls[0].Controls[0] as GridViewRow;
            if (((TextBox)emptyrow.FindControl("txtCode")).Text == "")

在页面加载中,我还通过编写以下代码进行了检查

gvNavigationDtls.DataBind();
            Control c = gvNavigationDtls.Controls[0].FindControl("txtCode");
            if (c != null)
            {
            }

但 c 为空,这意味着我无法找到使用它的控件,请帮助,在此先感谢

4

2 回答 2

3
protected void gvNavigationDtls_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("EInsert"))
        {
          TextBox txtCode=(TextBox)gvNavigationDtls.Controls[0].Controls[0].FindControl("txtCode");
          txtCode.Text="Your value";
        }
     }
于 2013-09-05T18:27:40.107 回答
1

实际上,刚刚遇到了这个问题,很容易找到访问数据,但它在 RowDataBound 事件中。

    Protected Sub grdView(sender As Object, e As GridViewRowEventArgs) Handles grdView.RowDataBound
        If e.Row.RowType = DataControlRowType.EmptyDataRow Then
            Dim txt As TextBox = e.Row.FindControl("txtBox")
            txt.Text = "Hey, this works!"
        End If
    End Sub
于 2016-06-10T11:38:35.610 回答