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

Problem to sort GridTemplateColumn with Image control

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gustavo
Top achievements
Rank 1
Gustavo asked on 14 Nov 2014, 11:16 AM
Hi,

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:

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

NeedDataSource and ItemDataBound events:
protected void radGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
  myTable = new DataTable();
 
  myTable.Columns.Add("RangeMin");
  myTable.Columns.Add("RangeMax");
  myTable.Columns.Add("ColorAux");
 
  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?

Thanks

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2014, 06:59 PM
Hi,

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

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Gustavo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or