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

How to get ControlID in ItemTempalate

3 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
trunghieu
Top achievements
Rank 1
trunghieu asked on 25 Apr 2011, 09:23 PM
Hello,i want get ControlID (<asp:image />) but this controlID belong ItemTemplate tag of Radgrid
This's CODE
<Columns>       
        <telerik:GridClientSelectColumn UniqueName="column1">
        </telerik:GridClientSelectColumn>       
        <telerik:GridTemplateColumn UniqueName="TemplateColumn">
            <ItemTemplate>
                  <asp:Image ID="okimg" BorderWidth="0px"  ImageUrl="hinh/MailFlagRed.png"
                               Style="float: right; cursor: pointer;" runat="server">
                            </asp:Image>
            </ItemTemplate>
        </telerik:GridTemplateColumn>       
    </Columns>
I also have two topics need help
http://www.telerik.com/community/forums/aspnet-ajax/grid/help-expand-button-in-radgrid.aspx
http://www.telerik.com/community/forums/aspnet-ajax/grid/clientselectcolumn-in-radgrid.aspx
Please Help Me
THANKS

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Apr 2011, 04:46 AM
Hello Trunghieu,

You can access the control by using the FindControl method. Here is a sample code.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           Image img = (Image)item.FindControl("okimg");//accessing the control
           Response.Write(img.ClientID);//accessing the properties
       }
   }

Also take a look at the help article.
Accessing Cells and Rows

Thanks,
Shinu.
0
trunghieu
Top achievements
Rank 1
answered on 06 May 2011, 10:18 AM
Hi Srr,some day i busy,now i have RadGrid2 in RadGrid1,so how to get controlID of RadGrid2,I want to dump data from datatable into Radgrid2,i using this code but not run
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               RadGrid g = item.FindControl("RadGrid2").ClientID;
          Stringtest = g.ClientID;
           }
       }
Please Help Me
THANK
0
Tsvetina
Telerik team
answered on 11 May 2011, 11:07 AM
Hello,

You are doing an incorrect cast. You should rather use:

RadGrid g = item.FindControl("RadGrid2") as RadGrid;
string gridId = g.ID; //for usage on the server-side
string clientId = g.ClientID; //for usage on the client-side


Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
trunghieu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
trunghieu
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or