2013-02-13 3 views
1
내가 기존 데이터가없는 상태 그리드에 새로운 데이터를 입력하는 EmptyDataTemplate을 사용하고

에 emptydatatemplate에서 컨트롤을 찾을 수 있지만, 나는 또한 페이지로드에 EmptyDateTemplate있는 gridview

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의

+0

가능한 중복 http://stackoverflow.com/questions/1584913/asp-net-gridview-emptydatatemplate –

+1

http://aspdotnetcodebook.blogspot.in/2009/03/how-to-find-control- inside.html –

+0

대단히 감사드립니다. 제 2의 코멘트에서 제공 한 솔루션을 제대로 사용할 수있게되었습니다. 각 단계가 코드에서 구현되었으므로, 대단히 감사합니다. Shekhar !!! – Anuj

답변

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"; 
     } 
    } 
+0

이 코드를 설명해 주시겠습니까? emptydatarowcontrols에 액세스하는 – hgwhittle

+0

. "emptydatarow의 주소를 참조하는 Control [0] .Controls [0]". –

+0

거기에 컨트롤 [0]에 대한 작업장이 없습니까? –

0

실제로이 문제가 발생하여 데이터에 쉽게 액세스 할 수 있지만 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 
+0

정말 고마워요! 그것은 일하고있다! 나는 많은 방법을 시도해 봤지만 그들 중 누구도 일하고 ​​있지 않았다. – user3707094

관련 문제