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

Javasript - Find a control (asp:image) in selected RadGrid Row

3 Answers 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wired_Nerve
Top achievements
Rank 2
Wired_Nerve asked on 01 Mar 2013, 04:11 PM
I have a radgrid and a user has made a choice in a radcombobox in a row.  I have then set the row selected to true (in javascript) and I also have reference to the rows index (if needed).  Anyway,  now I need to change a asp:image control and a asp:label controls values based on the combobox choice...

I was trying something like this (see script below) but it continues to return null... I would like to leverage the fact that I have the row set as selected if that would help actually find the image control

function getControl(rowIndex) {
var masterTable = $find("<%=RadGridAudits.ClientID%>").get_masterTableView();
var imageState = masterTable.get_dataItems()[rowIndex].findControl('ImageState');
// change the img to another image at this point...
 }

Here is the GridTemplageColumn:
<telerik:GridTemplateColumn DataField="TagAuditState" HeaderText="Audit State" SortExpression="TagAuditState"
                     UniqueName="TagAuditState">
                     <ItemTemplate>
                         <asp:Image ID="ImageState" runat="server" />
                         <asp:Label ID="LabelTagAuditState" runat="server" SkinID="EditForms" Text='<%# Eval("TagAuditState") %>' />
                     </ItemTemplate>
                 </telerik:GridTemplateColumn>

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 02 Mar 2013, 06:02 AM
Hi,

Try accessing the Image in the ItemTemplate using findElement instead of findControl as shown below.

Javascript:
var imageState = masterTable.get_dataItems()[rowIndex].findElement('ImageState');

Thanks,
Shinu.
0
Wired_Nerve
Top achievements
Rank 2
answered on 02 Mar 2013, 11:21 PM
What indicates you should use element versus control?
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 Mar 2013, 03:52 AM
Hi,

findElement method takes control id for an argument and returns the corresponding DOM element of html or rendered server control inside the grid row. Useful to reference html elements of controls inside a grid item cell on the client.

findControl method takes control id for an argument and returns the corresponding client object of RadControl or ASP.NET AJAX control inside the grid row. Useful to reference client objects of controls inside a grid item cell on the client.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" />
                    <telerik:RadTextBox ID="RadTextBox1" runat="server" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowDataBound="RadGrid1_RowDataBound" />
    </ClientSettings>
</telerik:RadGrid>

Javascript:
function RadGrid1_RowDataBound(sender, args) {
 
    var lbl = args.get_item().findElement("Label1");
    lbl.innerHTML = args.get_dataItem()["LastName"];
 
    var radTextBox1 = args.get_item().findControl("RadTextBox1");
    radTextBox1.set_value(args.get_dataItem()["TitleOfCourtesy"]);
}

Thanks,
Shinu.
Tags
Grid
Asked by
Wired_Nerve
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Wired_Nerve
Top achievements
Rank 2
Share this question
or