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

GridButtonColumn ImageButton equivalent of Datafield?

1 Answer 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 11 Feb 2009, 04:09 PM
Hi,
I'm trying to use an ImageButton column and have different images used based on the results of a query.  In other words, I will have a datacolumn which will have the url of the image to display.
For example on Page_Load if this were a normal GridBoundColumn I could do
if (dataColumn.ColumnName.ToString() == "myColumn"
     GridBoundColumn newColumn = new GridBoundColumn(); 
     this.RadGrid1.MasterTableView.Columns.Add(newColumn ); 
     newColumn.DataField = dataColumn.ColumnName; 

How would I do this to set the url of a GridButtonColumn?
buttonColumn.ImageUrl = dataColumn.ColumnName; 
Doesn't work; how do I accomplish this and where?
Thanks,
Nick


1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Feb 2009, 04:30 AM
Hello Nick,

You can set the DataKeyName of your MasterTableView to the DataField which holds the url of the image and then access the ImageButton of the ButtonColumn and set its ImageUrl as the datakeyvalue. To understand better check out the code below:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"
     <MasterTableView DataKeyNames="myColumn">        
      

cs:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridDataItem ) 
        {           
                GridDataItem edit = (GridDataItem)e.Item; 
                ImageButton img = (ImageButton)edit["Image"].Controls[0]; 
                img.ImageUrl = edit.GetDataKeyValue("myColumn").ToString(); 
             
        }  
 
    } 

Thanks
Princy.


Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or