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

GridImageColumn - ImageUrl

1 Answer 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Jul 2012, 08:27 AM
Hello

I'm having some problems trying to find the right code to display an image conditionally within a GridImageColumn.  I have looked through all of your examples and guides, and cannot find one that I can relate to.

All of my code is written in C# and the grid is generated programatically.

private readonly GridTableView detailTable;
private readonly RadGrid grid = new RadGrid();
 
private void InitialiseGrid()
        {
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "SearchGrid", Resources.SearchGrid, true);
 
            grid.ID = "grid";    
 
            grid.PagerStyle.AlwaysVisible = true;
 
            this.grid.ClientSettings.ClientEvents.OnRowDblClick = "SearchGridRowDoubleClick";
 
            this.grid.MasterTableView.Name = "Jobs";
            this.grid.MasterTableView.DataKeyNames = new[] { "BatchId" };
            this.grid.MasterTableView.ClientDataKeyNames = new[] { "Id" };
            this.grid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;
             
            this.grid.NeedDataSource += GridNeedDataSource;
            this.grid.DetailTableDataBind += GridDetailTableDataBind;
 
            this.grid.Columns.Add(new GridImageColumn { ImageUrl = "Images/Tasks.ico" });

The code above shows (with some properties stripped out) the Master Table View being initialised, and the use of the ImageUrl as one of the columns.  This works fine, showing an image directly from a stored location.  What I'm trying to do is set this value to what is stored within one of the Jobs object properties.

When I call the this.grid.NeedDataSource, this calls another method to calculate and populate the Jobs.  This runs the following code to populate the securityImage variable, which is then set into the Jobs Object and returned in the data source:

var securityImage = userHasSecurityLevel ? "Images/Edit1.png" : "Images/Delete.png"

All of my other columns are added using the following code:

this.grid.Columns.Add(new GridBoundColumn { DataField = "Surname", HeaderText = Resources.SurnameColumnText });
this.grid.Columns.Add(new GridBoundColumn { DataField = "Forename", HeaderText = Resources.FornameColumnText });

I have tried using the following to set the image, but this just throws an error, as the value is expecting to be received in an array format.  Are you able to help me understand whether this is the correct code to use, and if so, how to use it properly?

this.grid.Columns.Add(new GridImageColumn { DataImageUrlFields = "SecurityImage" });

Many thanks,

Mark

1 Answer, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 10 Jul 2012, 03:28 PM
Have just resolved this myself.

It was simply a coding misunderstanding, and have used the following to achieve what I wanted:

this.detailTable.Columns.Add(new GridImageColumn { DataImageUrlFields = new[] { "SecurityImage" }});

Cheers

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