1
votes

i am using EmptyDataTemplate for entering new data in grid while there is no existing data,but i am not able to find my controls in the 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 == "")

in page load also i checked by writing following code

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

but c is null,that means i am not able to find control to use it, Please help,Thanks in Advance

2
Thank u very much i got the solution which you provided in 2nd comment it worked properly i followed each step n implemented it in my code,thank u very much Shekhar!!! - Anuj

2 Answers

3
votes
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";
        }
     }
1
votes

Actually, just had this problem and it's really easy to find access the data but it's in the RowDataBound event.

    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