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

Add Image Column To Grid Dynamically

2 Answers 479 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 23 Nov 2009, 12:31 PM
I need to add a Template Column containing an image to a grid programmatically at Page Load time.  I have successfully added the column in the .aspx file, but do not know how to add the column in the code-behind file (using visual basic).  Here's the code for the .aspx file that I want to add:
        <MasterTableView NoMasterRecordsText="" AutoGenerateColumns="False" > 
            <Columns> 
                <telerik:GridTemplateColumn UniqueName="ImageFile" Groupable="False">  
                    <HeaderStyle ></HeaderStyle>  
                    <ItemStyle HorizontalAlign="Center" ></ItemStyle>  
                    <ItemTemplate> 
                        <asp:Image ID="ImportantImage" Height="40px" BorderWidth="0px" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>' AlternateText="Picture" runat="server" />                                          
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 
            </Columns> 
        </MasterTableView> 
 
Can anyone tell me how to add this same column in the Page Load event in the code behind file?  I have added data bound columns and hyperlinks (see code below), but don't know how to define the template column programmatically.
            hypercolumn = New GridHyperLinkColumn  
            Me.RadGrid1.Columns.Add(hypercolumn)  
            hypercolumn.HeaderText = "Edit Rec." 
            hypercolumn.Text = "Edit" 
            hypercolumn.DataNavigateUrlFields = New String() {"Item"}  
            hypercolumn.DataNavigateUrlFormatString = "~/ItemEdit.aspx?K={0}" 
            hypercolumn.UniqueName = "EditRec" 
            hypercolumn = Nothing 
 
Thanks in advance for any help!

Lynn

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 23 Nov 2009, 01:59 PM
Hello Lynn,

Please examine the following link:
Programmatic creation

Let me know if you need further assistance.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Lynn
Top achievements
Rank 2
answered on 15 Dec 2009, 03:24 PM
Daniel,

Sorry I didn't get this item closed out in a timely fashion.  I've been so busy I think I just forgot.  I did get this resolve with the help of your direction.  It's working fine and I'm combining images and hot links in the same columns.

I will admit that it takes a little time to understand the whole "template column" thing.  I still make some mistakes on occasion, but once you get it working, it works consistently.

Thanks!

Lynn
Tags
Grid
Asked by
Lynn
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Lynn
Top achievements
Rank 2
Share this question
or