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

radgrid itemtemplate and jquery

8 Answers 243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 10 Aug 2011, 10:04 PM
I'm trying to get an element id from inside a radgrid's GridTemplateColumn ItemTemplate.
But i keep getting 'btnContainer' does not exist in the current context.
How do i get it's id?


jquery:
 
document.getElementById('<%= btnContainer.ClientID %>')

radgrid:

<telerik:GridTemplateColumn>
      <ItemTemplate>
            <asp:LinkButton ID="btnContainer" class="ActionMenuButton" runat="server" >Actions</asp:LinkButton>
      </ItemTemplate>           
</telerik:GridTemplateColumn>

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Aug 2011, 05:08 AM
Hello Michael,

You can access the controls in ItemTemplate using findElement as shown below.
Javascript:
<script type="text/javascript">
 function ButtonClick()
  {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var masterTable = grid.get_masterTableView();
        var row = masterTable.get_dataItems();
        var button = row.findElement("btnContainer");
  }
</script>

Thanks,
Princy
0
Michael
Top achievements
Rank 1
answered on 11 Aug 2011, 02:40 PM
I tried that but I keep getting an error

Error: Object doesn't support property or method 'findElement'
0
Daniel
Telerik team
answered on 11 Aug 2011, 09:27 PM
Hello Michael,

findElement method is part of the item object and not of the items array:
var row = masterTable.get_dataItems()[0];
var button = row.findElement("btnContainer");

GridDataItem Class Members

Regards,
Daniel
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.

0
Michael
Top achievements
Rank 1
answered on 11 Aug 2011, 09:48 PM
That fixed the error but my button's OnCommand still isn't working inside the radgrid

row.findElement("btnContainer").click();
<asp:LinkButton ID="btnContainer" class="ActionMenuButton" runat="server" CommandName='<%#Eval("formID") + "," + Eval("isPublished")%>' OnCommand="action_Command">Actions</asp:LinkButton>
0
Daniel
Telerik team
answered on 17 Aug 2011, 10:50 AM
Hello Michael,

This code works fine on my end.
I created a simple demo based on these snippets. Please test it locally and see if I'm missing something.

Best regards,
Daniel
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.

0
Michael
Top achievements
Rank 1
answered on 17 Aug 2011, 04:15 PM

Thanks, seems to work but I'm needing to get the values from each row. How would I go about doing something like that? Here is what my action_Command looks like:

protected void action_Command(object sender, CommandEventArgs e)
    {
        string[] values = e.CommandName.Split(',');
        Globals.FormID = Convert.ToInt32(values[0]);
        Globals.IsPublished = values[1];
 
        Label1.Text = Globals.FormID + "";
        Label2.Text = Globals.IsPublished;
    }

0
Daniel
Telerik team
answered on 21 Aug 2011, 11:44 AM
Hello Michael,

I merged your code to my previous demo and added logic to display the values for each row.
Hope this helps.

Regards,
Daniel
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
prat
Top achievements
Rank 1
answered on 27 Sep 2011, 07:27 AM
I have a Radgrid and four textboxes in the item templates of each row.
On textchanged event of a textbox I want to loop through the radgrid using Jquery/JavaScript, sum up all the three textboxes and display it in the fourth textbox of the corresponding row..
Is there a solution?
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Daniel
Telerik team
prat
Top achievements
Rank 1
Share this question
or