Telerik Forums
UI for ASP.NET AJAX Forum
7 answers
308 views

Can someone help me figure out how to do this?  I need to change the color/shape of a datapoint based on a value in the datasource.  If a certain value for each datarow is empty, display one shape.  Otherwise, default to another shape.  

 Thanks!

David
Top achievements
Rank 1
Iron
Iron
Veteran
 answered on 11 Nov 2015
5 answers
85 views

I have devised a way perform several things I'm sure that many Telerik developers have wanted to be able to do, and seperately there are plenty of posts around these forums that assist in one or the other.  I've tried to use many of them myself, but ended up with a completely different solution, which I will descript how to do below:

 

I have a web application with dozens of screens, with dozens of grids on them, each with dozens of fields that require filtering.  Some of these screens return thousands of rows, and I was relying on client side filtering to make the web app easier to find what the user wanted.

 

I saw posts on how to use custom paging, but if you modify your code to return, say, only 50 rows per page and you are performing the paging in your query/stored procedure based on page number * page size, the client side filtering will only work on those 50 rows returned - even if there were matches on other pages that did not get returned in your result set.

 

Also, I wanted to persist my filters across pages, so that if I left that page and then later returned to it, my filters would still be intact and displayed.  I could not get any of the samples I found using google to work.

With persistent filtering in place, using standard paging so I could filter across my entire dataset (not just the set of pages that were returned via custom paging), with another small tweak I have been able to 'Turbo Charge' the performance of many of my screens.  I was able to take a screen that took 20 seconds to load and reduce it down to about 2 seconds.  The initial load (with no filtering in place) still takes 20 seconds, but once a filter is in place, it screams.

I will detail how this can be done as best I can as this is my first post to these forums.  I'm sure there are probably better ways to achieve what I have, but I'll post how I did it here anyway so any other people who want to do the same will have a framework to start from and improve upon.

The main 'trick' I used to boost the performance across an entire dataset was to pass a slightly modified form of the combined radgrid filterexpression to my sql stored procedure and make it part of my where clause, so that the procedure itself would tie it's results directly to the filters the user wanted and only return rows that matched the filters, which results in a HUGE performance boost when you are dealing with large recordsets because the filtering was done on the server side instead of the client side.

To achieve truly persistent filtering, first, turn off linq expressions in the page load sub and perform your first save and load of the persisted filters.  Note for multiple different pages you are implementing this on, the UniqueKeyForThisPageAndGrid will need to be, of course, unique.

<P>SessionStorageProvider.StorageProviderKey = "UniqueKeyForThisPageAndGrid"<BR>
       If Session("ProActSuppNegotiation") Is Nothing Then
RadPersistenceManager1.SaveState()<BR>       
RadPersistenceManager1.LoadState()</P>
<P><BR>RadGridBottom.EnableLinqExpressions = False</P>

Set up the session storage provider in your code behind page:

<P>Imports Telerik.Web.UI.PersistenceFramework</P>
<P>Private Sub [yourpage]_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init<BR>   
RadPersistenceManager1.StorageProvider = New SessionStorageProvider()<BR>End
Sub</P>


Add this new sub in your page (make sure to use your unique column names, and your radgrid name)

private sub SetFiltersForSql()<BR>   if not ispostback
then<BR>      Dim ac As
GridColumn<BR>      Dim fv As
String<BR>      Dim newFE As String =
""<BR>      ac =
yourgrid.MasterTableView.GetColumnSafe("ContractNo")<BR>     
ac.CurrentFilterFunction =
GridKnownFunction.Contains<BR>      fv =
ac.CurrentFilterValue<BR>      If Trim(fv) <> ""
Then newFE = "([ContractNo] LIKE '%" + fv +
"%')"<BR>      ac =
yourgrid.MasterTableView.GetColumnSafe("SupplierName")<BR>     
ac.CurrentFilterFunction =
GridKnownFunction.Contains<BR>      fv =
ac.CurrentFilterValue<BR>      If Trim(fv) <> ""
Then newFE = newFE + "([SupplierName] LIKE '%" + fv +
"%')"<BR>      ac =
yourgrid.MasterTableView.GetColumnSafe("StartDate")<BR>     
ac.CurrentFilterFunction =
GridKnownFunction.Contains<BR>      fv =
ac.CurrentFilterValue<BR>      If Trim(fv) <> ""
Then newFE = newFE + "([StartDate] LIKE '%" + fv +
"%'<BR>      'etc etc...for each filtered column you
want to use.<BR><BR>      newFE = Replace(newFE,
"')([", "') AND ([")<BR>     
RadGridBottom.MasterTableView.FilterExpression =
newFE<BR>      'Now that the filter expression is
stored in the radgrid the way radgrid wants it, we have to tweak it a little bit
so it will also work as a passed parameter to our sql stored
procedure:<BR>      'We need to get rid of the open and
close parenthesis.<BR>      'We need to plug
'placeholders' in for the quoted left and right side of each filter
expression.<BR>      '(plugging in the placeholders is
needed so we can properly quote the actual filter expressions without messing
with the sql syntax required for it to work as a part of a where clause. 
The stored procedure will handle returning the placeholders back to
quotes.)<BR>      newFE = Replace(newFE, "(",
"")<BR>      newFE = Replace(newFE, ")",
"")<BR>      newFE = Replace(newFE, "'%",
"|%")<BR>      newFE = Replace(newFE, "%'",
"%|")<BR>      newFE =
FixSql(newFE)<BR>      If newFE Is Nothing
Then<BR>         newFE =
"*"<BR>      End If<BR>     
'set our correctly formed sql expression into the session.  this will
become part of a where clause.<BR>     
Session("psnsql") = newFE<BR>   end if<BR>end sub


In the radgrid_DataBinding function, collect the filters as follows:
<BR>Private Sub yourgrid_DataBinding(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RadGridTop.DataBinding<BR>    If Not
IsPostBack Then<BR>       
SetFiltersForSql()<BR>    End If<BR>End Sub


Now, in the radgrid ItemCommand sub, check for filter operations and save the state of the filters and such.  Keep in mind, there is a unique key in the code below that you must set for each and every different grid, on each and every different page you want to persist seperately.

Private Sub yourgrid_ItemCommand(ByVal sender As Object, ByVal e As
Telerik.Web.UI.GridCommandEventArgs) Handles
RadGridBottom.ItemCommand<BR>    If e.CommandName =
RadGrid.FilterCommandName Or e.CommandName = "ChangePageSize" Or e.CommandName =
"Sort" Or e.CommandName = "Page"
Then<BR>       
SessionStorageProvider.StorageProviderKey =
"UniqueKeyForThisPageAndGrid"<BR>       
RadPersistenceManager1.SaveState()<BR>       
SetFiltersForSql()<BR>       
yourgrid.Rebind()<BR>    End If<BR>End Sub


To Retain the saved Page number you were on, this function is needed (and called from the page load).  If you have multiple grids on the same page, use this function to check and set each one.  Remember to use your page name and your grid name followed by "PageIndex", not the hardcoded text below:

Private Sub SetPageNumber()<BR>    If
Session("PageNameGridNamePageIndex") = "" Then
Session("PageNameGridNamePageIndex") = "0"<BR>   
yourgrid.CurrentPageIndex = CInt(Session("PageNameGridNamePageIndex"))<BR>End
Sub

You will also need to implement these:

Private Sub RadGridBottom_PageIndexChanged(ByVal sender As Object, ByVal e As
Telerik.Web.UI.GridPageChangedEventArgs) Handles
RadGridBottom.PageIndexChanged<BR>    Session("PageNameGridNamePageIndex") =
e.NewPageIndex.ToString()<BR>   
SessionStorageProvider.StorageProviderKey =
"UniqueKeyForThisPageAndGrid"<BR>   
RadPersistenceManager1.SaveState()<BR>End Sub<BR><BR>Private Sub
RadGridBottom_PageSizeChanged(ByVal sender As Object, ByVal e As
Telerik.Web.UI.GridPageSizeChangedEventArgs) Handles
RadGridBottom.PageSizeChanged<BR>    If
Session("PageNameGridNamePageSize") = e.NewPageSize
Then<BR>        e.Canceled = True 'cancel
bubbled event so page variable doesn't get reset<BR>   
Else<BR>       
Session("PageNameGridNamePageSize") =
e.NewPageSize<BR>       
Session("PageNameGridNamePageIndex"))= "0" 'must reset since old page # won't be
same as new page # on different page size.<BR>    End
If<BR>    SessionStorageProvider.StorageProviderKey =
"UniqueKeyForThisPageAndGrid"<BR>   
RadPersistenceManager1.SaveState()<BR>    End Sub

Now, you need to ensure that the datasource your grid is using allows for the special sql expression as a parameter.  In this example code, I have used session variables so that it also persists across pages.

In your asp page, add the radpersistencemanager for your grid(s):

<telerik:RadPersistenceManager ID="RadPersistenceManager1" runat="server"
><BR>   
<PersistenceSettings><BR>       
<telerik:PersistenceSetting ControlID="yourgrid" /><BR>   
</PersistenceSettings><BR></telerik:RadPersistenceManager>

In your asp page for the <ASP:SqlDataSourceID> being used by your radgrid, add:

<asp:SessionParameter Name="clause" SessionField="psnsql" Type="String" />

Also Add

"@clause varchar(1024)"
as a parameter to your stored procedure.

And finally, the stored procedure will get some rework done to it.  You can't pass a piece of a where clause to a procedure and expect it to work.  What you need to do is convert your sql code to a large string, then add the passed in piece of the where clause to it, and execute the string. There are a couple things to do to the procedure first.  Inside your stored procedure, add these lines above your select statement:

These lines declare a needed variable and replace the parameters in the string with left and right quotes to surround your LIKE clauses.

Declare @sql varchar(4096)<BR>set @clause = replace(@clause, '|%', '''%')<BR>set
@clause = replace(@clause, '%|', '%''')

Next, since your database schema table fields may not be named exactly like the UniqueID's you specified in your radgrid, we need to replace them with their actual table field counterparts (remember to use the table qualifiers like a. and b. etc if needed by your actual query)

select @clause = replace(@clause, '[ContractNo]', 'a.contractno')<BR>select
@clause = replace(@clause, '[SupplierName]', 'b.Company')<BR>select @clause =
replace(@clause, '[StartDate]', 'a.startdate')

Now, you need to convert your original query into a string.  Take care to modify any parameters that were passed in to still be used properly by building them into the string similarly as we do below with our new @clause variable.

set @sql='Select a.CID, a.ContractNo, a.SupplierNo, b.Company as SupplierName,
'<BR>set @sql = @sql + 'from CMS_Contracts a '<BR>set @sql = @sql + 'join
vendors b on a.SupplierNo = b.VendNo ' + <BR>set @sql = @sql + 'where
a.supplierno = b.vendno '

--and now add your passed in piece of the where clause and execute the code:
if @clause <> '*' and isnull(@clause, '') <> '' set @sql = @sql + '
and ' + @clause<BR>exec (@sql)

And that's it.  I know this mish mash of code in this post might be a bit much to chew on, but I wanted to share my success with persistent filtering and turbo filtered results on large datasets.  Feel free to try and incorporate what I have been able to achieve in your own code.  Even if you choose NOT to use the sql modifications here, this is a really neat way to persist all the filtered columns across pages.

- Patrick

Kostadin
Telerik team
 answered on 11 Nov 2015
1 answer
170 views

I have a code something like this.

I have a code something like this.
 
  
 
 <telerik:RadAjaxManager ID="ajaxManager" runat="server">
        <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="PagePanel">
        <UpdatedControls>
        <telerik:AjaxUpdatedControl ControlID="PagePanel" LoadingPanelID="ViewsLoadingPanel" />
        </UpdatedControls>
        </telerik:AjaxSetting>
        </AjaxSettings>
        </telerik:RadAjaxManager>
         
   <telerik:RadAjaxLoadingPanel ID="ViewsLoadingPanel" runat="Server" Skin="Default" />
 
   <telerik:RadAjaxPanel ID="PagePanel" runat="server">
 
 <asp:Repeater ID="rptrTabItems" runat="server" OnItemDataBound="rptrTab_OnItemDataBound">
                    <ItemTemplate>
                        <asp:LinkButton Style="display: block; padding-left:2px; padding- top:2px; border: 1px solid black; text-align: left" ID="lnkbtnTab" runat="server"         CommandArgument="" CommandName="" OnClick="TabClick_Click" />
                    </ItemTemplate>
                </asp:Repeater>
 
<asp:PlaceHolder ID="phViews">
 
 // I have nested repeaters here and lots of controls.....
 
</asp:PlaceHolder>​
 
</telerik:RadAjaxPanel>
 
//Code behind to ajaxify Link Button
  
 ajaxManager.AjaxSettings.AddAjaxSetting(((LinkButton)e.Item.FindControl("lnkbtnTab")), PagePanel, ViewsLoadingPanel);
​

 

Im trying to show loadingpanel on the click of linkbutton. its not showing. the processing time on click takes atleast 5-10 seconds.

Maria Ilieva
Telerik team
 answered on 11 Nov 2015
4 answers
921 views
Hello Telerik Team,

I have tried to export data from Radgrid via Excel-Format="ExcelML". The problem is, how to "autofit" column's width when cell content is too wide to fit in the column ? Normally in excel, user can double click between columns header and it automatically expands its width.
More info is here: http://www.launchexcel.com/column-width-autofit-keyboard/

The question is, how to do it from C# code ?

Thank you for your help.

Best regards.

Vasssek
Kostadin
Telerik team
 answered on 11 Nov 2015
4 answers
74 views

I have a multiple document upload page in which a cancel button can be clicked before all the files selected are finished uploading. Along with this, I am utilizing the RadProgressManager and RadProgressArea to display the progress. When clicking cancel, I am clearing the file list in the code behind and hiding the upload panel then showing the document list. When I click to upload again and toggle the panels the RadProgressArea is still displaying with the same information that it had stopped at when clicking the cancel button. The upload procedure continues to work but the Progress never updates. If I click cancel after all the files upload, everything works as expected. I know there is functionality to suppress a postback until file uploads are completed this but I'd prefer to allow this.

 I have tried ​enabling/disabling the RadProgressManager and RadProgressArea, manually updating the ProgressData client side to reset it.

 

Any help would be appreciated.

Peter Filipov
Telerik team
 answered on 11 Nov 2015
1 answer
276 views

I have a RadGrid with a GridDateTimeColumn, with a DatePicker filter.   The From & To inputs with calendar popup appear in the filter row.   I would like to have this split across 2 lines as it makes the column very wide - and it's a waste of space.    I have tried setting the FilterControlWidth and that just changes the size of the input text box.    Here is the aspx code for the column and a pic of the column:  

                    <telerik:GridDateTimeColumn  DataField="CreateDate" SortExpression="create_dt" UniqueName="CreateDate" 
                        PickerType="DatePicker" DataType="System.DateTime" DataFormatString="{0:MMM d, yyyy}"
                        EnableRangeFiltering="true" FilterDateFormat="MMM d, yyyy" 
                        HeaderStyle-Wrap="true" FilterControlWidth="120px">
                            <HeaderStyle Width="100px" Wrap="true"></HeaderStyle>     
                    </telerik:GridDateTimeColumn>

 

How do I go about getting the filter row to wrap or split across 2 lines?

Thanks

Janice

 

 

Maria Ilieva
Telerik team
 answered on 11 Nov 2015
4 answers
96 views
Hello .
First Let me talk about my Problem . I have an Grid and I want a Column of CheckBoxes that when You click On an Input/Button (Or checkbox in Header) ,All of CheckBoxes Checked,ClientSidely Not ServerSidely.There are some Pages in Telerik.com But Unfortunately I didn't Understand :-) Like this :
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/selecting/row-selection/defaultcs.aspx
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/selecting/selecting-rows/client-side-selecting-with-a-click
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/selecting/selecting-rows/client-side-selecting-multiple-rows
It's Complicated
. Please Send me a Complete and simple Solution .for example Simple Grid with Minimum Items and Required Methods, properties and any Changes that we Need.
Thanks in Advance
Mahdi
Top achievements
Rank 1
 answered on 11 Nov 2015
1 answer
158 views

Hi I am not able to solve this error The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

 

this is my script

 

<body>
 

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager2" runat="server" />
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxManager EnableAJAX="true" ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="FormView1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="FormView1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>


     <telerik:RadScriptBlock  ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            var FormName = "frmPerformMaintRecurringAS";
            var FormId = 71;
            var UserId = '<%= Session["UserId"] %>';
            EntityID = FormId;
            var tabstrip;
        </script>
    </telerik:RadScriptBlock>​

 

 

what am doing wrong?

Sam
Top achievements
Rank 1
 answered on 11 Nov 2015
14 answers
396 views

I'm using Chrome 11 / Firefox 4 (2010.3.1317.40) and suddenly the ajax updates started working in a strange way.
Looking at inspector:

Uncaught Error: SYNTAX_ERR: DOM Exception 12:
On Telerik.Web.UI.WebResource.axd: 1136

The line is this one:

}if(d[b].indexOf("{")!=-1){e.insertRule(d[b]+"}",e.cssRules.length);
Telerik.Web.UI.WebResource.axd:1136Uncaught Error: SYNTAX_ERR: DOM Exception 12
After this the page crashes, no refresh / recompile helps in solving this problem. Is this a bug?
Ahmed
Top achievements
Rank 1
 answered on 11 Nov 2015
1 answer
112 views

Hi all

 I have a pop up modal window, which itself has a further pop up window.

I have Teleriks script to refresh the underlying window:

 And for the first pop up its works fine, problem is I have the same script on the second pop up, but the GetRadWindow() returns oWindow is undefined.

What do I need to do to get the GetRadWindow() to find both the original page and the first pop up?

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
 
function CloseAndRebind(args) {
  GetRadWindow().BrowserWindow.refreshGrid();
  GetRadWindow().Close();
}

 

Marin Bratanov
Telerik team
 answered on 11 Nov 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?