Hi,
Is it possible to show sort icons on all columns at page load.I go through this link " http://www.telerik.com/community/forums/aspnet/grid/possible-to-show-sort-icon-regardless-sort-status.aspx ."But still i am not able to find the solution.On page load i need to show Sort icon on all columns.Please help me ?
Thanks in Advance
Joby
Is it possible to show sort icons on all columns at page load.I go through this link " http://www.telerik.com/community/forums/aspnet/grid/possible-to-show-sort-icon-regardless-sort-status.aspx ."But still i am not able to find the solution.On page load i need to show Sort icon on all columns.Please help me ?
Thanks in Advance
Joby
10 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 20 Dec 2011, 09:47 AM
Hello,
One suggestion is you can try the following code snippet to show sort icon image on all columns.
CS:
-Shinu.
One suggestion is you can try the following code snippet to show sort icon image on all columns.
CS:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridHeaderItem)
{
GridHeaderItem header = (GridHeaderItem)e.Item;
Image img =
new
Image();
img.ID =
"Image1"
;
img.ImageUrl =
"~/Images/sort arrow.gif"
;
foreach
(GridBoundColumn col
in
RadGrid1.Columns)
{
header[col.UniqueName].Controls.AddAt(1, img);
if
(RadGrid1.MasterTableView.SortExpressions.Count != 0 && RadGrid1.MasterTableView.SortExpressions[0].FieldName == col.UniqueName)
{
if
(RadGrid1.MasterTableView.SortExpressions[0].SortOrder != GridSortOrder.None)
{
header[col.UniqueName].Controls.Remove(img);
}
}
}
}
-Shinu.
0

Joby
Top achievements
Rank 1
answered on 20 Dec 2011, 10:04 AM
Hi,
Thanks for the reply.....I have both Bounded column and Template column.From this code image is showing only for last column.I am not expecting that.I need to show sort image for all columns in the grid instead of last column at page load only.
Thanks for the reply.....I have both Bounded column and Template column.From this code image is showing only for last column.I am not expecting that.I need to show sort image for all columns in the grid instead of last column at page load only.
0
Shinu's code uses a single image control for all columns. The image is added to each column consecutively, and gets removed from the previous column. Thus, it ends up in the last column. You need to use an Image for every column
Veli
the Telerik team
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridHeaderItem)
{
GridHeaderItem header = (GridHeaderItem)e.Item;
foreach
(GridBoundColumn col
in
RadGrid1.Columns)
{
Image img =
new
Image();
img.ID =
"Image1_"
+ col.UniqueName;
//each image needs to have a unique ID
img.ImageUrl =
"~/Images/sort arrow.gif"
;
header[col.UniqueName].Controls.AddAt(1, img);
if
(RadGrid1.MasterTableView.SortExpressions.Count != 0 && RadGrid1.MasterTableView.SortExpressions[0].FieldName == col.UniqueName)
{
if
(RadGrid1.MasterTableView.SortExpressions[0].SortOrder != GridSortOrder.None)
{
header[col.UniqueName].Controls.Remove(img);
}
}
}
}
Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

Joby
Top achievements
Rank 1
answered on 20 Dec 2011, 10:58 AM
Hi,
Thank you for the reply...In the above code i am getting this error "Unable to cast object of type 'Telerik.Web.UI.GridTemplateColumn' to type 'Telerik.Web.UI.GridBoundColumn'.".Because i have both Bound column and Template column in my grid.I need to show Sort images for all columns both Bound and Template
Thank you for the reply...In the above code i am getting this error "Unable to cast object of type 'Telerik.Web.UI.GridTemplateColumn' to type 'Telerik.Web.UI.GridBoundColumn'.".Because i have both Bound column and Template column in my grid.I need to show Sort images for all columns both Bound and Template
0
Try changing the column type in the foreach loop:
Veli
the Telerik team
foreach
(GridColumn col
in
RadGrid1.Columns)
{
if
(col
is
GridBoundColumn || col
is
GridTemplateColumn)
{
...
}
}
Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

Chris
Top achievements
Rank 1
answered on 28 Jan 2014, 03:34 PM
I was able to use this to assign an 'unsorted' image to my column header, but the image doesnt align well like the built-in images do. Any tips on getting the images to fit up against the right side of the text?
Currently sometimes it appears as if the image 'word wrapped' below the column title, sometimes its on the left of the text, sometimes it looks about right.
Currently sometimes it appears as if the image 'word wrapped' below the column title, sometimes its on the left of the text, sometimes it looks about right.
0

Shinu
Top achievements
Rank 2
answered on 29 Jan 2014, 06:10 AM
Hi Chris,
I was not able to replicate the issue. In the above code snippet we are accessing the HeaderItem and Columns. Using this line of code we set the position of the image:
See the attached image. Please provide your code snippet if this doesn't help.
Thanks,
Shinu
I was not able to replicate the issue. In the above code snippet we are accessing the HeaderItem and Columns. Using this line of code we set the position of the image:
header[col.UniqueName].Controls.AddAt(1, img);
//For the Image to be right of HeaderText
header[col.UniqueName].Controls.AddAt(0, img);
//For the Image to be left of HeaderText
See the attached image. Please provide your code snippet if this doesn't help.
Thanks,
Shinu
0

Shinu
Top achievements
Rank 2
answered on 29 Jan 2014, 06:29 AM
Hi Chris,
The image was not attached properly in the previous post. Here is the image of the page I obtained.
Thanks,
Shinu
The image was not attached properly in the previous post. Here is the image of the page I obtained.
Thanks,
Shinu
0

Chris
Top achievements
Rank 1
answered on 29 Jan 2014, 06:59 PM
It turns out for certain columns there were more than one control in the array, so AddAt(1 was adding it somewhere in the middle.
0

Shinu
Top achievements
Rank 2
answered on 30 Jan 2014, 03:14 AM
Hi Chris,
With so little information I'm not able to replicate the issue. Please provide your code snippet.
Thanks,
Shinu
With so little information I'm not able to replicate the issue. Please provide your code snippet.
Thanks,
Shinu