Please help,
I have a grid with programmatically created columns, depending on what columns the user wants shown.
However I cannot get the filtering to work. The filter box is there and it allows me to enter a value, but it will go away and think about it and comes back with an empty filter box and nothing happens. It basically does nothing.
I have looked through all the properties of a bound column and can't see anything I havent set.
Thanks for your help, I love these controls :)
I have a grid with programmatically created columns, depending on what columns the user wants shown.
| If column("DATA_TYPE") = "varchar" Or column("DATA_TYPE") = "nvarchar" Then |
| Dim boundcol As New GridBoundColumn() |
| boundcol.UniqueName = column("FullName") |
| boundcol.HeaderText = column("FriendlyColumnName") |
| boundcol.DataField = column("FullName") |
| boundcol.HeaderTooltip = boundcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| boundcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| gridServers.MasterTableView.Columns.Add(boundcol) |
| boundcol.SortExpression = column("FullName") |
| boundcol.Groupable = True |
| boundcol.GroupByExpression = column("FullName") + " Group By " + column("FullName") |
| boundcol.AllowFiltering = True |
However I cannot get the filtering to work. The filter box is there and it allows me to enter a value, but it will go away and think about it and comes back with an empty filter box and nothing happens. It basically does nothing.
I have looked through all the properties of a bound column and can't see anything I havent set.
Thanks for your help, I love these controls :)
9 Answers, 1 is accepted
0
Nick
Top achievements
Rank 1
answered on 05 Jun 2009, 12:15 PM
Sorry the code should be
but the same thing happens ....
Cheers.
| Dim boundcol As New GridBoundColumn() |
| boundcol.UniqueName = column("FullName") |
| boundcol.HeaderText = column("FriendlyColumnName") |
| boundcol.DataField = column("FullName") |
| boundcol.HeaderTooltip = boundcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| boundcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| boundcol.SortExpression = column("FullName") |
| boundcol.Groupable = True |
| boundcol.GroupByExpression = column("FullName") + " Group By " + column("FullName") |
| boundcol.AllowFiltering = True |
| gridServers.MasterTableView.Columns.Add(boundcol) |
but the same thing happens ....
Cheers.
0
Nick
Top achievements
Rank 1
answered on 08 Jun 2009, 08:13 AM
Can anyone point me in the right direction please? I'm te4aring my hair out with this.
Many thanks.
Nick
Many thanks.
Nick
0
Hi Nick,
I went through your code and it looks fine. However, could you please specify where are you creating your grid, on Page_Load or on Page_Init?
If the columns are added on Page_Init, the code for adding them you used is proper. But if you are adding them on Page_Load, try modifying it as below:
Additionally, could you share how is your grid bound and if paging, sorting work properly?
Regards,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
I went through your code and it looks fine. However, could you please specify where are you creating your grid, on Page_Load or on Page_Init?
If the columns are added on Page_Init, the code for adding them you used is proper. But if you are adding them on Page_Load, try modifying it as below:
| Dim boundcol As New GridBoundColumn() |
| gridServers.MasterTableView.Columns.Add(boundcol) |
| boundcol.UniqueName = column("FullName") |
| boundcol.HeaderText = column("FriendlyColumnName") |
| boundcol.DataField = column("FullName") |
| boundcol.HeaderTooltip = boundcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| boundcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| boundcol.SortExpression = column("FullName") |
| boundcol.Groupable = True |
| boundcol.GroupByExpression = column("FullName") + " Group By " + column("FullName") |
| boundcol.AllowFiltering = True |
Additionally, could you share how is your grid bound and if paging, sorting work properly?
Regards,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nick
Top achievements
Rank 1
answered on 08 Jun 2009, 12:45 PM
I'm grateful for your reply.
The grid is created declaratively like so :
| <telerik:RadGrid ID="gridServers" AutoGenerateColumns="False" CssClass="gridServers" OnUpdateCommand="gridServers_UpdateCommand" runat="server" AllowPaging="True" GridLines="None" AllowSorting="True" AllowFilteringByColumn="True" ShowGroupPanel="True"> |
| <ClientSettings AllowColumnsReorder="True" EnableRowHoverStyle="True" |
| ReorderColumnsOnClient="True" AllowDragToGroup="True"> |
| <Selecting AllowRowSelect="True" /> |
| <Scrolling AllowScroll="True" UseStaticHeaders="True" /> |
| </ClientSettings> |
| <MasterTableView EditMode="PopUp" EnableHeaderContextMenu="True"> |
| <EditFormSettings><PopUpSettings Modal="True" /></EditFormSettings> |
| <EditItemStyle BackColor="PowderBlue" /> |
| </MasterTableView> |
| <EditItemStyle BackColor="Transparent" /> |
| </telerik:RadGrid> |
Proababnly not the best way - mixing methods, but I had started this grid off using autogenerated columns, eveything was working fine then (!)
Then the gridcolumns are prepared when needdatasource is called :
| Protected Sub gridServers_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridServers.NeedDataSource |
| 'Set up grid columns acording to our selected column list |
| PrepareGridColumns() |
| Dim value() As String = {"Device ID"} |
| gridServers.DataSource = GetDataTable() |
| gridServers.MasterTableView.DataKeyNames = value |
| End Sub |
| Public Function GetDataTable() As DataTable |
| Dim ConnString As String = ConfigurationManager.ConnectionStrings("WPG_ADBConnectionString").ConnectionString |
| Dim conn As SqlConnection = New SqlConnection(ConnString) |
| Dim adapter As SqlDataAdapter = New SqlDataAdapter |
| adapter.SelectCommand = New SqlCommand(getDataString(), conn) |
| Dim table1 As New DataTable |
| conn.Open() |
| Try |
| adapter.Fill(table1) |
| Finally |
| conn.Close() |
| End Try |
| Return table1 |
| End Function |
Here is the prepareGridColumns()
| Public Sub PrepareGridColumns() |
| 'This function will generate the columns for the Grid by looping through the checkbox datatable |
| ' Instead of autogenerating, this way I can handpick and identify the dropdown\lookup columns |
| Dim column As DataRow |
| Dim columnList As DataTable = Session("showColumns") |
| Dim AnyColumnsAreEditable As Boolean = False |
| 'Clear Columns |
| gridServers.Columns.Clear() |
| Dim editcol As New GridEditCommandColumn() |
| gridServers.MasterTableView.Columns.Add(editcol) |
| For Each column In columnList.Rows |
| If column("Checked") Then |
| If column("LookupTable") <> "" Then |
| Dim sql As New SqlDataSource |
| sql.ID = "sql" & column("Table_Name") & column("column_Name") |
| sql.ConnectionString = ConfigurationManager.ConnectionStrings("WPG_ADBConnectionString").ConnectionString |
| sql.SelectCommand = "select " & column("LookupID") & ", " & column("LookupValue") & " from " & column("LookupTable") |
| Dim dropdowncol As New GridDropDownColumn |
| dropdowncol.ListValueField = column("LookupID") |
| dropdowncol.ListTextField = column("LookupValue") |
| dropdowncol.DataSourceID = sql.ID |
| dropdowncol.HeaderText = column("FriendlyColumnName") |
| dropdowncol.DataField = column("FullName") |
| dropdowncol.UniqueName = column("FullName") |
| dropdowncol.ReadOnly = Boolean.Parse(column("Readonly")) |
| dropdowncol.SortExpression = column("FullName") |
| 'dropdowncol.Groupable = True |
| 'dropdowncol.GroupByExpression = column("FullName") + " Group By " + column("FullName") |
| dropdowncol.AllowFiltering = True |
| gridServers.Columns.Add(dropdowncol) |
| Else |
| If column("DATA_TYPE") = "varchar" Or column("DATA_TYPE") = "nvarchar" Then |
| Dim boundcol As New GridBoundColumn() |
| boundcol.UniqueName = column("FullName") |
| boundcol.HeaderText = column("FriendlyColumnName") |
| boundcol.DataField = column("FullName") |
| boundcol.HeaderTooltip = boundcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| boundcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| boundcol.SortExpression = column("FullName") |
| 'boundcol.Groupable = True |
| 'boundcol.GroupByExpression = column("FullName") + " Group By " + column("FullName") |
| boundcol.AllowFiltering = True |
| gridServers.MasterTableView.Columns.Add(boundcol) |
| ElseIf column("DATA_TYPE") = "datetime" Then |
| Dim datecol As New GridDateTimeColumn() |
| datecol.UniqueName = column("FullName") |
| datecol.HeaderText = column("FriendlyColumnName") |
| datecol.DataField = column("FullName") |
| datecol.HeaderTooltip = datecol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| datecol.ReadOnly = Boolean.Parse(column("Readonly")) |
| datecol.PickerType = GridDateTimeColumnPickerType.DateTimePicker |
| gridServers.MasterTableView.Columns.Add(datecol) |
| ElseIf column("DATA_TYPE") = "int" Or column("DATA_TYPE") = "bigint" Then |
| Dim intcol As New GridNumericColumn() |
| intcol.UniqueName = column("FullName") |
| intcol.HeaderText = column("FriendlyColumnName") |
| intcol.DataField = column("FullName") |
| intcol.HeaderTooltip = intcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| intcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| gridServers.MasterTableView.Columns.Add(intcol) |
| ElseIf column("DATA_TYPE") = "text" Then |
| 'Dim HTMLcol As New GridHTMLEditorColumn() |
| 'HTMLcol.UniqueName = column("FullName") |
| 'HTMLcol.HeaderText = column("FriendlyColumnName") |
| 'HTMLcol.DataField = column("FullName") |
| 'HTMLcol.HeaderTooltip = HTMLcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| 'HTMLcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| 'HTMLcol.EditFormColumnIndex = 0 |
| 'gridServers.MasterTableView.Columns.Add(HTMLcol) |
| Dim tempcol As New GridTemplateColumn() |
| 'The class for this template can be found at the bottom of this code-behind |
| tempcol.EditItemTemplate = New MyTemplate(column("FullName")) |
| tempcol.UniqueName = column("FullName") |
| tempcol.HeaderText = column("FriendlyColumnName") |
| tempcol.DataField = column("FullName") |
| tempcol.HeaderTooltip = tempcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| tempcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| gridServers.MasterTableView.Columns.Add(tempcol) |
| ElseIf column("DATA_TYPE") = "bit" Then |
| Dim Checkcol As New GridCheckBoxColumn() |
| Checkcol.UniqueName = column("FullName") |
| Checkcol.HeaderText = column("FriendlyColumnName") |
| Checkcol.DataField = column("FullName") |
| Checkcol.HeaderTooltip = Checkcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| Checkcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| gridServers.MasterTableView.Columns.Add(Checkcol) |
| Else |
| Dim boundcol As New GridBoundColumn() |
| boundcol.UniqueName = column("FullName") |
| boundcol.HeaderText = column("FriendlyColumnName") |
| boundcol.DataField = column("FullName") |
| boundcol.HeaderStyle.ForeColor = Drawing.Color.Red |
| boundcol.HeaderTooltip = boundcol.HeaderTooltip.ToString() + " - " + column("FullName") & " - " & column("Description") |
| boundcol.ReadOnly = Boolean.Parse(column("Readonly")) |
| gridServers.MasterTableView.Columns.Add(boundcol) |
| End If |
| End If |
| End If |
| Next |
| End Sub |
Please excuse the ugly code (!)
The paging and sorting works fine. It is the filtering which seems to do nothing (goes to server via ajax and returns to just clear the filter box), and when trying to group by dragging columns, I receive the "Expression cannot be null or empty" client side. - doesn't even go to the server.
I have tried setting GridBoundColumn.Groupable, GridBoundColumn.GroupByExpression, GridBoundColumn.AllowFiltering for each column to no avail.
I'm using RadControls for ASP.NET AJAX Q1 2009
Thanks for your assistance. If you could offer a best practice to initialise the grid entirely in the code behind
0
Nick
Top achievements
Rank 1
answered on 08 Jun 2009, 12:55 PM
Amazing,
Both problems were solved by your suggestion - adding the created column to the column collection before settings up it's properties.
I don't see why this makes a difference technically, but it's made me happy!
many thanks, Iana .
Nick
Both problems were solved by your suggestion - adding the created column to the column collection before settings up it's properties.
I don't see why this makes a difference technically, but it's made me happy!
many thanks, Iana .
Nick
0
Hi Nick,
You can review this article and see the differences between dynamic grid creation on Page_Load and Page_Init.
Do not hesitate to write back if you get any questions.
Sincerely yours,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can review this article and see the differences between dynamic grid creation on Page_Load and Page_Init.
Do not hesitate to write back if you get any questions.
Sincerely yours,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nick
Top achievements
Rank 1
answered on 09 Jun 2009, 07:43 AM
Thank you for your help up to now.
My only query now is that, once you have dynamically created a grid control in page_init, I don't know how to handle events for the control as :
a) my code-behind doesn't know about the control anymore and therefore my Handles do not work
b) The control doesn't allow me to set onColumnCreated="DoThis" (for example).
I suppose this is more about my lack of knowledge in VB in general but if you can suggest how this is worked around I would be a very happy man.
Thanks again.
Nick
My only query now is that, once you have dynamically created a grid control in page_init, I don't know how to handle events for the control as :
a) my code-behind doesn't know about the control anymore and therefore my Handles do not work
b) The control doesn't allow me to set onColumnCreated="DoThis" (for example).
I suppose this is more about my lack of knowledge in VB in general but if you can suggest how this is worked around I would be a very happy man.
Thanks again.
Nick
0
Nick
Top achievements
Rank 1
answered on 09 Jun 2009, 08:06 AM
I use addHandler in page_init too, don't I.
Just testing you!
| AddHandler grid.ColumnCreated, AddressOf gridServers_ColumnCreated |
Just testing you!
0
Hello Nick,
Indeed, you got the right direction with the AddHandler clause.
Kind regards,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Indeed, you got the right direction with the AddHandler clause.
Kind regards,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.