FindControl inside RadGrid FormTemplateEditForm

7 posts, 2 answers
  1. Catalina
    Catalina avatar
    9 posts
    Member since:
    Apr 2012

    Posted 18 Jun 2012 Link to this post

    If i use RadGrid in this way (http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx), and if inside that FormTemplateEditForm i have another RadGrid, how can i "find" it? If I use (RadGrid)this.Master.FindControl("RadGrid2") i get a null value.

    How cand i acces some controls in TemplateEditForm? How can i "find" them?
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Jun 2012 Link to this post

    Hi Catalina,

    Try the following code to access controls inside FormTemplate.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
     if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
     {
       GridEditFormItem editForm = (GridEditFormItem)e.Item;
       RadGrid grid = (RadGrid)editForm.FindControl("RadGrid2");
     }  
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Catalina
    Catalina avatar
    9 posts
    Member since:
    Apr 2012

    Posted 18 Jun 2012 Link to this post

    Yes, this works. But, for example, if in "RadGrid1_UpdateComand", i want to acces some controls inside FormTemplate (my RadGrid2 or anything ele) how can i do that?
  5. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 18 Jun 2012 Link to this post

    Hello catalina,

    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditFormItem editForm = (GridEditFormItem)e.Item;
            RadGrid grid = (RadGrid)editForm.FindControl("RadGrid2");
        }


    Thanks,
    Jayesh Goyani
  6. Catalina
    Catalina avatar
    9 posts
    Member since:
    Apr 2012

    Posted 18 Jun 2012 Link to this post

    One more question:

    I want to access controls inside FormTemplate from page_load, or something like this  ... is this possible?

  7. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 12 Jun 2015 in reply to Jayesh Goyani Link to this post

    Hi Jayesh

     

     i want assign value to control which is inside grideditformitem on radgrid_editcommand event.

     for example textbox inside the grideditformitem on click edit link in the grid i want to assign some value to textbox text property.

    /Regards

    Bharath.

     

  8. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 16 Jun 2015 in reply to Shinu Link to this post

    Hello,

    Please try with the below code snippet.

     

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
        OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"></telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <asp:TextBox ID="txtID" runat="server" Text='<%# Eval("ID") %>'></asp:TextBox>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
            new { ID = 1, Name ="Name1"},
            new { ID = 2, Name ="Name2"}
        };
        RadGrid1.DataSource = data;
    }
     
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
        {
            GridEditFormItem editForm = (GridEditFormItem)e.Item;
            TextBox txtName = (TextBox)editForm.FindControl("txtName");
            txtName.Text = "jayesh";
        }
    }

    Let me know if any concern.

    Thanks,

    Jayesh Goyani

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017