FindControl GridTemplateColumn Outside of radGrid Events

9 posts, 1 answers
  1. Justin
    Justin avatar
    24 posts
    Member since:
    Sep 2011

    Posted 02 Nov 2011 Link to this post

    I have my own method and I am trying to findcontrol on a control inside the GridTemplateColumn, so I am doing it outside of the events for the radGrid. Is this possible and if so, how?

    Thanks!
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Nov 2011 Link to this post

    Hello Justin,

    You can try the following code snippet to access the controls in a GridTemplateColumn.
    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
     foreach (GridDataItem item in RadGrid1.Items)
     {
       LinkButton lbtn = (LinkButton)item["ColUniqueName"].FindControl("LinkButton1");
     }
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 17 Apr 2013 Link to this post

    Hi,
       i am  using nestedradgridview.In that i have one grid when i am clicking on Expand column i am going to display an panel inside that panel i have radTabstrip and RadMultiPageView.when i am clicking on pirticular tab i am displaying pageview.Again in that pageview i have multiple linkedbottons.When ever i clicked on linked buttons i want to display individual rad-grid's.

                    Now when i am clicking on the linkbutton iam unalbe to find the inner Radgrid GridTemplateColumn control.The following is my Code..Please Help me.

    i want just like this..http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx.
    But i want to bind data using .cs file only.
    i am writing code as follows but it is not working..

    protected
    void Button1_Click(object sender, EventArgs e)
    {
        GridNestedViewItem nestedView = (GridNestedViewItem)(sender as LinkButton).NamingContainer;
            RadGrid gridPaperCost1 = (RadGrid)nestedView.FindControl("RadGrid33");
            
            foreach (GridDataItem item in gridPaperCost1.Items)
            {
                TextBox lbtn = (TextBox)item["NoOfUps"].FindControl("textbox2");
            }
    }
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Apr 2013 Link to this post

    Hi,

    Try the following.
    C#:
    protected void Button2_Click(object sender, EventArgs e)
    {
            foreach (GridNestedViewItem nestedView in RadGrid2.MasterTableView.GetItems(GridItemType.NestedView))
            {
                RadGrid gridPaperCost1 = (RadGrid)nestedView.FindControl("RadGrid33");
                foreach (GridDataItem item in gridPaperCost1.Items)
                {
                    TextBox lbtn = (TextBox)item.FindControl("textbox2");
                }
            }
    }

    Thanks,
    Shinu
  6. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 18 Apr 2013 Link to this post

    hi,
       i tried with your code..But the control did not enter into  the Below loop atleast  once.
    So please help me...
    foreach (GridDataItem item in gridPaperCost1.Items)
                {
                    TextBox lbtn = (TextBox)item.FindControl("textbox2");
                }
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Apr 2013 Link to this post

    Hi,

    The above code is working as expected in my end. If the button is inside nestedview, you can access the row using NamingContainer and then access the inner grid using findcontrol method. If the button is outside the grid, loop through the nested item and get reference to the controls. Hope this helps.

    Thanks,
    Shinu
  8. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 19 Apr 2013 Link to this post

    Hi,
      in Button is inside my nested grid only.
    But i am trying to execute your code it will not enter into inner for loop..
    i am getting gridPaperCost1.Items as null..
    So please help me..
  9. Balakrishna Reddy
    Balakrishna Reddy avatar
    37 posts
    Member since:
    Oct 2012

    Posted 19 Apr 2013 Link to this post

    <telerik:RadGrid ID="gridCustomerEnquiry" runat="server" AutoGenerateColumns="False" Width="100%"
                    AllowPaging="True" PageSize="20" GridLines="None" CellSpacing="0"
                    OnItemCommand="gridCustomerEnquiry_ItemCommand">
                    <MasterTableView DataKeyNames="EstimationID">
                        <Columns>
                                   <--------------grid colummns------------>
                       </columns>
                <NestedViewTemplate>
                                <asp:Panel runat="server" ID="InnerContainer" Width="100%" CssClass="viewWrap" Visible="true"> 
                                        <telerik:RadTabStrip ID="tabStrip" runat="server" SelectedIndex="0" MultiPageID="multipage">
                                            <Tabs>
                                                <telerik:RadTab Text="Size" PageViewID="PageView1">
                                                </telerik:RadTab>
                                             </Tabs>
                                </telerik:RadTabStrip>
     <telerik:RadMultiPage ID="multipage" runat="server">
    <telerik:RadPageView ID="PageView1" runat="server">
                             <asp:LinkButton ID="LinkButton32" runat="server" Text="ADD/EDIT" OnClick="LinkButton32_Click" />
                                                            <h4>
                                                                Paper Cost</h4>
                                                            <telerik:RadGrid ID="RadGrid33" runat="server" AllowPaging="false" Width="100%" AutoGenerateColumns="false"
                                                                GridLines="Both" Skin="WebBlue">
                                                                <MasterTableView >
                                                                    <Columns>
                                                                        <telerik:GridBoundColumn DataField="S.No" HeaderText="Sl No" UniqueName="sno" HeaderStyle-Width="5%"
                                                                            ReadOnly="true">
                                                                        </telerik:GridBoundColumn>
                                                                        <telerik:GridTemplateColumn DataField="NoOfUps" HeaderText="No Of Ups" HeaderStyle-Width="10%"
                                                                            UniqueName="NoOfUps">
                                                                            <ItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox2" runat="server" />
                                                                            </ItemTemplate>
                                                                            <EditItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox2" runat="server" />
                                                                            </EditItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn DataField="NoOfOuts" HeaderText="No Of Outs" HeaderStyle-Width="10%"
                                                                            UniqueName="NoOfOuts">
                                                                            <ItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox3" runat="server" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn DataField="Wastage" HeaderText="Wastage" HeaderStyle-Width="10%"
                                                                            UniqueName="Wastage">
                                                                            <ItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox4" runat="server" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn DataField="Spoilage" HeaderText="Spoilage" HeaderStyle-Width="10%"
                                                                            UniqueName="Spoilage">
                                                                            <ItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox5" runat="server" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn DataField="SheetsRequired" HeaderText="Sheets Required"
                                                                            HeaderStyle-Width="10%" UniqueName="SheetsRequired">
                                                                            <ItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox6" runat="server" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn DataField="EachSheetCost" HeaderText="Each Sheet Cost"
                                                                            HeaderStyle-Width="10%" Aggregate="Sum" UniqueName="EachSheetCost">
                                                                            <ItemTemplate>
                                                                                <telerik:RadTextBox ID="textbox7" runat="server" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                    </Columns>
                                                                </MasterTableView>
                                                                <ClientSettings>
                                                                    <Scrolling AllowScroll="true" />
                                                                    <ClientEvents OnCommand="showLoadingPanel" />
                                                                </ClientSettings>
                                                            </telerik:RadGrid>
                                                            <asp:Button ID="Button66" Text="Ok/Hide" runat="server" OnClick="Button66_Click" />
                                    </telerik:RadPageView>
                                     </telerik:RadMultiPage>
                                </asp:Panel>
                        </NestedViewTemplate>
                    </MasterTableView>
                </telerik:RadGrid>

    This is my aspx code.and my .cs file is like.

    protected void LinkButton32_Click(object sender, EventArgs e)
        {
            GridNestedViewItem nestedView = (GridNestedViewItem)(sender as LinkButton).NamingContainer;
            System.Web.UI.HtmlControls.HtmlGenericControl div = (System.Web.UI.HtmlControls.HtmlGenericControl)nestedView.FindControl("div46");
            div.Visible = true;
            RadPageView pageView = (RadPageView)nestedView.FindControl("PageView11");
            RadGrid gridPaperCost = (RadGrid)pageView.FindControl("RadGrid33");
            

            foreach(GridNestedViewItem nestedViewItem in gridCustomerEnquiry.MasterTableView.GetItems(GridItemType.NestedView))
            {
                RadGrid gridPaperCost1 = (RadGrid)nestedViewItem.FindControl("RadGrid33");
                foreach(GridDataItem item in gridPaperCost1.Items)  //control not enter into inside this for loop..
                {
                    TextBox lbtn = (TextBox)item.FindControl("textbox2");
                }
            }
    }
  10. Rajnish
    Rajnish avatar
    1 posts
    Member since:
    Dec 2013

    Posted 17 Feb 2015 Link to this post

    Respected sir 

                              How to access nested(child) grid on any palces, as like on any method,  i am easily accessing child grid within  Main(Parent) grid events and controls. but i want to access Child Grid out side of Grid controls and events.. . How to do this.?...

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