FindControl GridTemplateColumn

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

    Posted 28 Oct 2011 Link to this post

    I have a RadGrid with a GridTemplateColumn like so:

    <telerik:GridTemplateColumn HeaderText="Account" UniqueName="Account">
        <ItemTemplate>
            <div>
                <asp:DropDownList ID="ddlAccountLookup" Visible="false" runat="server">
                </asp:DropDownList>
                <asp:Label ID="grdAccountName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AccountName") %>' /><br />
                <asp:Label ID="grdPhone" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Phone") %>' /><br />
                <asp:Label ID="grdEmail" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Email") %>' />
            </div>
        </ItemTemplate>
        <HeaderStyle CssClass="BigNormalBold" HorizontalAlign="Left" VerticalAlign="Bottom" />
        <ItemStyle CssClass="Normal" />
    </telerik:GridTemplateColumn>


    I need to find the ddlAccountLookup and make it Visible on PostBack, how would I go about doing this?

    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2011 Link to this post

    Hello Justin,

    You can try the following code snippet in ItemDataBound event to access the DropDownList.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridDataItem)
     {
       GridDataItem item = (GridDataItem)e.Item;
       DropDownList ddl=(DropDownList)item.FindControl("ddlAccountLookup");
       ddl.Visible = true;
     }
    }

    Thanks,
    Shinu.
  3. Justin
    Justin avatar
    24 posts
    Member since:
    Sep 2011

    Posted 28 Oct 2011 Link to this post

    Thanks for the reply. I tried that and it never goes into the If statement. When I set a Breakpoint it says the if is false because Item is a GridItemHeader. Any idea?

    Thanks!
  4. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 29 Oct 2011 Link to this post

    Hello,

    <telerik:GridTemplateColumn UniqueName="CTest">
                          <HeaderTemplate>
                              <asp:TextBox ID="hTextBox" runat="server"></asp:TextBox>
                          </HeaderTemplate>
                          <ItemTemplate>
                              <asp:TextBox ID="iTextBox" runat="server"></asp:TextBox>
                          </ItemTemplate>
                          <FilterTemplate>
                              <asp:TextBox ID="fTextBox" runat="server"></asp:TextBox>
                          </FilterTemplate>
                          <FooterTemplate>
                              <asp:TextBox ID="fooTextBox" runat="server"></asp:TextBox>
                          </FooterTemplate>
                      </telerik:GridTemplateColumn>
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    ((e.Item as GridDataItem)["CTest"].FindControl("iTextBox") as TextBox).Text = "item";
                }
                if (e.Item is GridHeaderItem)
                {
                    ((e.Item as GridHeaderItem)["CTest"].FindControl("hTextBox") as TextBox).Text = "headeritem";
                }
                if (e.Item is GridFilteringItem)
                {
                    ((e.Item as GridFilteringItem)["CTest"].FindControl("fTextBox") as TextBox).Text = "filteritem";
                }
                if (e.Item is GridFooterItem)
                {
                    ((e.Item as GridFooterItem)["CTest"].FindControl("fooTextBox") as TextBox).Text = "footeritem";
                }
            }


    Thanks,
    Jayesh Goyani
  5. Von Aaron
    Von Aaron avatar
    6 posts
    Member since:
    Oct 2011

    Posted 06 May 2013 Link to this post

    Thanks you so much for this code snippet, ive been looking for this in days, due to having a hard time figuring out.. on how to find the control inside the GridTemplateColumn ... really helped me...  thanks 
  6. Swati
    Swati avatar
    7 posts
    Member since:
    Jan 2017

    Posted 24 Jul 2017 in reply to Jayesh Goyani Link to this post

    Hi Jayesh,

    I am finding difficulty to get GridTemplateColumn Checkbox item template value in ItemCommand event.

    I want those values while Update of record.  Could please help how we can find  GridTemplateColumn control in Item Command event ?

     

    Thanks in advance.

Back to Top