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

Change ImageUrl of RadBinaryImage embeded in a Template Item on clientside

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Monsi Lache
Top achievements
Rank 1
Monsi Lache asked on 30 Oct 2010, 08:03 AM
Hi there,

Please help... I've been hitting my head on the wall for over a day on this. Searched and search but cannot find close solution...
Here is my problem.

I have a Radgrid that has a RadBinaryImage in the first cell of each row. I'm binding my grid on the clientside using json. I want to be able to change the image of the rows from clientside based on a criterion upon

ClientEvents-OnRowDataBound.

Here is my snippet:


ASPX:
-----------------

<telerik:RadGrid ID="RadReqOverview" runat="server" >
 <MasterTableView TableLayout= "Auto" EnableViewState="true">
  <Columns>
   <telerik:GridTemplateColumn HeaderStyle-Width="25px" UniqueName = "FLAG">
    <ItemTemplate>
                    <telerik:RadBinaryImage runat ="server" ID="IMGFLAG" Visible = "true" ImageUrl = "./Images/Open.png" />
    </ItemTemplate>
        </telerik:GridTemplateColumn>
  </Columns>
 </MasterTableView> 
 <ClientSettings ClientEvents-OnRowDataBound = "RowDataBound">
        <Selecting AllowRowSelect="True" />
        <Scrolling AllowScroll="True" />
 </ClientSettings>
</telerik:RadGrid>

 

Clientside(Javascript) 

 

 

---------------------------------

 

<script type="text/javascript">
           function RowDataBound(sender, args) {
           //Get handle of binaryimage for this cell upon databound
           var img = args.get_item().findControl("IMGFLAG"); //This is not working!!!!!!!!!
             if (img != null) {
                    // conditional formatting
                    // After I do my logic I want to change the image to closed
                   img.ImageUrl = "./Images/Closed.png";
               }
           }
</Script>

However this is not working!!! Please help. Thanks.

 

 

 

1 Answer, 1 is accepted

Sort by
0
Monsi Lache
Top achievements
Rank 1
answered on 02 Nov 2010, 01:33 AM
No problem, I fixed my issue by using:

//Javascript onRowDataBound event handler
//Note: I got rid of the RadBinaryImage in the cell and just used a background image of the template cell as follows:-
 

.function

 

RowDataBound(sender, args)
{

    if(<some condition is true>)
    {
        //Change the image in the cell called 'FLAG' to High.png
        args.get_item().get_cell("FLAG").style.background = "url('./Images/High.png') no-repeat scroll center center";
    }
    else
    {
         //Change the image in the cell called 'FLAG' to Medium.png
        args.get_item().get_cell("FLAG").style.background = "url('./Images/Medium.png') no-repeat scroll center center";
    }
}

Hope this will help somebody who gets stuck like I did... :)

Tags
Grid
Asked by
Monsi Lache
Top achievements
Rank 1
Answers by
Monsi Lache
Top achievements
Rank 1
Share this question
or