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

[Solved] access Image in GridDropDownColumn

2 Answers 103 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ebenezer
Top achievements
Rank 1
Ebenezer asked on 30 May 2013, 08:58 PM
I have a GridDropDownColumn with some columns. I want when a user select a "Status Color"  an Image of the color selected shows up next to it. I am using the code below is not working.

 <telerik:GridDropDownColumn  DataField="RiskStatusColorID" DataSourceID="StatusColorDataSource"
                                                            DefaultInsertValue="" HeaderText="Status Color" SortExpression="StatusColorID"
                                                            ListTextField="RiskStatusColor" ListValueField="StatusColorID" UniqueName="StatusColorID" DropDownControlType= "RadComboBox"> 
                                                         </telerik:GridDropDownColumn>
                                                          <telerik:GridTemplateColumn UniqueName="Images"  HeaderText="Images" > 
                                                             <ItemTemplate>
                                                             <asp:Image ID="Image1" runat="server" /> 
                                                             </ItemTemplate> 
                                                          </telerik:GridTemplateColumn> 


CodeBehind
---------------------
protected void gvSummary_ItemCreated(object sender, GridItemEventArgs e)
    {

GridEditableItem imgitem = (GridEditableItem)e.Item;
            RadComboBox imglist = (RadComboBox)imgitem["StatusColorID"].Controls[0];
            imglist.AutoPostBack = true;
            imglist.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(img_SelectedIndexChanged);
}
protected void img_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox comboimg = (RadComboBox)o;
        GridEditableItem edit2 = (GridEditableItem)comboimg.NamingContainer;
        if (comboimg.SelectedValue == "Red")
        {
            Image img = (Image)edit2.FindControl("Images");
            img.ImageUrl = "../Images/dot_red.png";
        }
        
}
 


                                                                                         

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 May 2013, 05:09 AM
Hi,

Please make sure that you are giving the correct 'ID' for the image in SelectedIndexChanged event.   Please specify which edit mode you are using. I have tried the same using InPlace edit mode and here is the sample I tried.

C#:
protected void img_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox comboimg = (RadComboBox)o;
    GridEditableItem edit2 = (GridEditableItem)comboimg.NamingContainer;
        
    if (comboimg.SelectedValue == "red")
    {
        Image img = (Image)edit2.FindControl("Image1");
        img.ImageUrl = "~/Images/red.png";
    }
}

Thanks,
Princy.
0
Ebenezer
Top achievements
Rank 1
answered on 31 May 2013, 12:42 PM
Hi Princy,
Thanks a lot you are right. Changing the ID works
  case "1":
            Image img = (Image)edit2.FindControl("Image1");
            img.ImageUrl = "~/Images/black.png";
            break;
Tags
General Discussions
Asked by
Ebenezer
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ebenezer
Top achievements
Rank 1
Share this question
or