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:
NeedDataSource and ItemDataBound events:
Any sugest how I can fix that problem?
Thanks
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