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

How to add 3 different images to 3 different rows in radGrid?

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 26 Feb 2009, 04:56 PM
Hi,

I am binding a datatable ( which has 3 columns & 3 rows) to a grid.
And after that now I am adding externally one more column called Image (contains image) to grid using ItemTemplate column as follows:

<

telerik:RadGrid ID="RadGrid1" runat="server" >

 

 

 

<MasterTableView

 

 

 

<Columns>

 

 

 

<telerik:GridTemplateColumn HeaderText="image" UniqueName="TemplateColumn">

 

 

 

<ItemTemplate>

 

 

 

<asp:ImageButton ID="Img" runat="server" ImageUrl="~/images/image1.gif" />

 

 

 

</ItemTemplate>

 

 

 

</telerik:GridTemplateColumn>

 

 

 

</Columns>

 

 

 

</MasterTableView>

 

 

 

</telerik:RadGrid>

but I want to add 3 different images in 3 rows how could I do that ?
can any one help out solving the problem

Thanks,

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Feb 2009, 04:45 AM
Hi Ram,

Try setting the ImageUrl for the ImageButton in each row in the ItemDataBound event of the Grid as shown below.

CS:
 
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = e.Item as GridDataItem; 
            ImageButton imgbtn = (ImageButton)item["TemplateColumn"].FindControl("Img"); 
            if (item.ItemIndex == 0) 
                imgbtn.ImageUrl = "~/images/image1.gif"
            else if (item.ItemIndex == 1) 
                imgbtn.ImageUrl = "~/images/image2.gif"
            else if (item.ItemIndex == 2) 
                imgbtn.ImageUrl = "~/images/image3.gif"
 
 
        }   
    } 


Thanks
Shinu
Tags
Grid
Asked by
Ram
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or