access Image in GridDropDownColumn

3 posts, 0 answers
  1. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 30 May 2013 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 May 2013 Link to this post

    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.
  3. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 31 May 2013 Link to this post

    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;
Back to Top