Problem to sort GridTemplateColumn with Image control

2 posts, 0 answers
  1. Gustavo
    Gustavo avatar
    23 posts
    Member since:
    Apr 2012

    Posted 14 Nov 2014 Link to this post


    I'm using a GridTemplateColumn with an Image control in ItemTemplate. I'm using the ItemDataBound event to set the Image background, this all works fine. However when I click on a column to sort all the text columns are sorted correctly but the images do not move.

    Here is my code:

    <telerik:RadGrid ID="radGrid1" runat="server" AllowSorting="true" OnNeedDataSource="radGrid1_NeedDataSource" OnItemDataBound="radGrid1_ItemDataBound">
      <MasterTableView EditMode="Batch" AllowSorting="true">
          <telerik:GridClientDeleteColumn ConfirmText="Are you sure?" ImageUrl="~/Images/icoDelete.png" />
          <telerik:GridTemplateColumn HeaderText="Color" UniqueName="RangeColor" DataField="RangeColor" ItemStyle-HorizontalAlign="Center">
                <asp:Image ID="imgRangeColor" Height="15" Width="100%" runat="server" />
                <telerik:RadColorPicker ID="colorPickerTemplate" runat="server" OnClientLoad="PickerLoad" ShowIcon="true" ShowEmptyColor="false" />
        <ClientEvents OnBatchEditGetCellValue="OnBatchEditGetCellValue" OnBatchEditSetCellValue="OnBatchEditSetCellValue" OnBatchEditGetEditorValue="OnBatchEditGetEditorValue" OnBatchEditSetEditorValue="OnBatchEditSetEditorValue" />

    NeedDataSource and ItemDataBound events:
    protected void radGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
      myTable = new DataTable();
      if (ViewState["Table"] != null)
        myTable = (DataTable)ViewState["Table"];
      radGrid1.DataSource = myTable;
      ViewState["Table"] = myTable;
    protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
      if (e.Item is GridDataItem & e.Item.IsDataBound)
        GridDataItem item = (GridDataItem)e.Item;
        string color = ((DataTable)ViewState["Table"]).Rows[item.ItemIndex][2].ToString(); //Get ColorAux value
        (item["RangeColor"].FindControl("imgRangeColor") as System.Web.UI.WebControls.Image).BackColor = System.Drawing.ColorTranslator.FromHtml(color);

    Any sugest how I can fix that problem?

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 14 Nov 2014 in reply to Gustavo Link to this post


    Could you please provide sample data for field "RangeColor" ?

    Jayesh Goyani
Back to Top