This is a migrated thread and some comments may be shown as answers.

FindControl GridTemplateColumn

5 Answers 444 Views
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 28 Oct 2011, 04:20 PM
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!

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 29 Oct 2011, 04:46 AM
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.
0
Justin
Top achievements
Rank 1
answered on 29 Oct 2011, 04:56 AM
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!
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 29 Oct 2011, 09:45 AM
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
0
Von Aaron
Top achievements
Rank 2
answered on 06 May 2013, 08:01 AM
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 
0
Swati
Top achievements
Rank 1
answered on 24 Jul 2017, 12:19 PM

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.

Tags
Grid
Asked by
Justin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Justin
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Von Aaron
Top achievements
Rank 2
Swati
Top achievements
Rank 1
Share this question
or