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 は null です。つまり、それを使用するためのコントロールを見つけることができません。助けてください。よろしくお願いします。

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 に答える