Hello all,
I want to have a label to display the grid row count and the columns sorts. I have multi sorting in the grid and by default it is sorted with 3 colmns and the user can still sort other column but I want the label to keep changing everytime the user is sorting the grid with the sequence the grid is sorted with.
Thank you for your help,
Shehab
I want to have a label to display the grid row count and the columns sorts. I have multi sorting in the grid and by default it is sorted with 3 colmns and the user can still sort other column but I want the label to keep changing everytime the user is sorting the grid with the sequence the grid is sorted with.
Thank you for your help,
Shehab
5 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 22 May 2008, 07:56 AM
Hi Shehab,
Use the Aggregate property of the column to display the count in the Grid.
ASPX:
Using columns
Thanks
Princy.
Use the Aggregate property of the column to display the count in the Grid.
ASPX:
| <telerik:GridBoundColumn Aggregate="Count" DataField="ProductID" DataType="System.Int32" HeaderText="ProductID" |
| SortExpression="ProductID" UniqueName="ProductID"> |
| </telerik:GridBoundColumn> |
Using columns
Thanks
Princy.
0
Shehab
Top achievements
Rank 1
answered on 22 May 2008, 11:07 AM
Hi Princy,
Thank you for that, I am also trying to display what columns are sorting the grid, like everytime the user sorts a column, I want to be able to change the label to display the header of the columns that are sorting the grid.
Thanks,
Shehab
Thank you for that, I am also trying to display what columns are sorting the grid, like everytime the user sorts a column, I want to be able to change the label to display the header of the columns that are sorting the grid.
Thanks,
Shehab
0
Shinu
Top achievements
Rank 2
answered on 22 May 2008, 12:43 PM
Hi Shehab,
Try the following code snippet to achieve the desired scenario.
CS:
Thanks
Shinu.
Try the following code snippet to achieve the desired scenario.
CS:
| protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| if (e.Item is GridFooterItem) |
| { |
| GridFooterItem footer = (GridFooterItem)e.Item; |
| Label lbl = new Label(); |
| lbl.ID = "lblFooter"; |
| footer["columnUniqueName"].Controls.Add(lbl); |
| } |
| } |
| public static string sortexp = ""; |
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == "Sort") |
| { |
| sortexp = ((System.Web.UI.WebControls.LinkButton)(e.CommandSource)).Text.ToString(); |
| } |
| } |
| protected void RadGrid1_PreRender(object sender, EventArgs e) |
| { |
| foreach (GridFooterItem footer in RadGrid1.MasterTableView.GetItems(GridItemType.Footer)) |
| { |
| Label lbl = (Label)footer.FindControl("lblFooter"); |
| lbl.Text = sortexp; |
| } |
| } |
Thanks
Shinu.
0
Shehab
Top achievements
Rank 1
answered on 23 May 2008, 12:29 PM
Hi Shinu,
Thank you for the respond, I tried to convert the code to VB.NET and it keeps throwing this error in the ItemDataBound:
Unable to cast object of type 'Telerik.WebControls.GridDataItem' to type 'Telerik.WebControls.GridFooterItem'.
here is the code:
Thank you for the respond, I tried to convert the code to VB.NET and it keeps throwing this error in the ItemDataBound:
Unable to cast object of type 'Telerik.WebControls.GridDataItem' to type 'Telerik.WebControls.GridFooterItem'.
here is the code:
| Protected Sub rgSearchResults_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles rgSearchResults.ItemDataBound |
| If TypeOf e.Item Is Telerik.WebControls.GridDataItem Then |
| Dim item As GridDataItem = CType(e.Item, GridDataItem) |
| Dim drv As DataRowView = CType(item.DataItem, DataRowView) |
| If drv("Observation") = True Then |
| CType(item.FindControl("Observation"), Label).Text = "Yes" |
| End If |
| Dim footer As GridFooterItem = DirectCast(e.Item, GridFooterItem) |
| Dim lbl As New Label() |
| lbl.ID = "lblFooter" |
| footer("columnUniqueName").Controls.Add(lbl) |
| End If |
| End Sub |
0
Shinu
Top achievements
Rank 2
answered on 26 May 2008, 04:25 AM
Hi Shehab,
Try the following VB code.
VB:
Thanks
Shinu.
Try the following VB code.
VB:
| Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) |
| If TypeOf e.Item Is GridFooterItem Then |
| Dim footer As GridFooterItem = DirectCast(e.Item, GridFooterItem) |
| Dim lbl As New Label() |
| lbl.ID = "lblFooter" |
| footer("columnUniqueName").Controls.Add(lbl) |
| End If |
| End Sub |
| Public Shared sortexp As String = "" |
| Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) |
| If e.CommandName = "Sort" Then |
| sortexp = DirectCast((e.CommandSource), System.Web.UI.WebControls.LinkButton).Text.ToString() |
| End If |
| End Sub |
| Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) |
| For Each footer As GridFooterItem In RadGrid1.MasterTableView.GetItems(GridItemType.Footer) |
| Dim lbl As Label = DirectCast(footer.FindControl("lblFooter"), Label) |
| lbl.Text = sortexp |
| Next |
| End Sub |
Thanks
Shinu.