Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
396 views
This all started when I found myself having issues with the RadGrid export. I did a little research and developed the following solution:
  1. Find a suitable library to generate the Excel file (should be free)
  2. Find a suitable library to compress the generated file as they could be quite large (again, should be free)
  3. Develop a generic method for doing all of the above

The answer to #1 was ClosedXML developed by Manuel De Leon
The answer to #2 was to use the DotNetZipLib

#3 took a little work, but the result was an extender to IEnumerable:

public static String ToExport<dynamic> ( this IEnumerable<dynamic> DataList, String ExcelFileName )
{
var WorkBook = new XLWorkbook ();
var ws = WorkBook.Worksheets.Add ( "Sheet1" );
ws.Cell ( 1, 1 ).InsertTable ( DataList );
String FileName = Path.GetRandomFileName ();
FileName = Path.ChangeExtension ( FileName, "zip" );
String FullFileName = Path.Combine ( HttpContext.Current.Server.MapPath ( "~/Exports" ), FileName );

using ( MemoryStream wbStream = new MemoryStream () )
{
WorkBook.SaveAs ( wbStream );
wbStream.Seek ( 0, SeekOrigin.Begin );

using ( ZipFile Archive = new ZipFile ( FullFileName ) )
{
Archive.AddEntry ( ExcelFileName + ".xlsx", wbStream );
Archive.Save ();
}
}

return ( "~/Exports/" + FileName ).ToAbsoluteUrl ();
}

As you can see, I am creating an Excel 2007+ file and compressing it into a temporary zip file in a folder within the web site. I then return the URL for the file.

In the page, I set the source for a hidden iframe to the URL.

The other part of this is the communication from the client to the code behind. To do that, I use the PageMethods part of the RadScriptManager to call the method in the page code behind. This means that I will not have access to any page variables as it has to be a static method. In order to access the LinqDataSource query and any parameters it uses, I save them to Session variables in the Selecting event:

Session [ "DeviceBurnHoursPageDataSource" ] = this.GridDataSource;
Session [ "DeviceBurnHoursPageFilter" ] = this.ReportGrid.MasterTableView.FilterExpression;
Session [ "DeviceBurnHoursPageReportDate" ] = this.ReportDate;

And then in the page method:

IDataSource TheSource = ( IDataSource ) HttpContext.Current.Session [ "DeviceBurnHoursPageDataSource" ];
LinqDataSourceView TheView = TheSource.GetView ( "DefaultView" ) as LinqDataSourceView;
DateTime ReportDate = ( DateTime ) HttpContext.Current.Session [ "DeviceBurnHoursPageReportDate" ];
String Filter = ( String ) HttpContext.Current.Session [ "DeviceBurnHoursPageFilter" ];

if ( Filter != String.Empty )
{
String W = " && " + Filter.Replace ( " AND ", " && " );
TheView.Where += W;
}

TheView.WhereParameters [ "ReportDate" ].DefaultValue = ReportDate.ToString ( "MM/dd/yyyy" );
DataSourceSelectArguments Args = new DataSourceSelectArguments ();

return ( ( IEnumerable<dynamic> ) TheView.Select ( Args ) ).ToExport ( "Device Burn Hours " + ReportDate.ToString ( "yyyy-MM-dd" ) );

The returned file is ALL of the columns returned by the query in the order they are defined. In this case, it is suitable for creating the Pivot Table in Excel. If you are exporting from a RadGrid, you should end-up with a ready-to-use Excel file.

I am certain that there are more elegant ways of doing this, but it works for me.

Kostadin
Telerik team
 answered on 04 Mar 2013
5 answers
88 views
Several users here have expressed interest in modifying the main grid in my application so that they can set which columns to display and how wide they are.

I think I have enough of a handle on the grid to implement something like this but I was wondering if there were any demos along this line.  (To avoid re-inventing the wheel.) 
Eyup
Telerik team
 answered on 04 Mar 2013
6 answers
984 views
Hi Telerik Support,

I am having a problem with RadComboBox. I am not able to select the first item of RadComboBox programmatically. I have instantiated  a RadComboBox with 2 columns. I am giving user the ability to filter combo box based upon items present either in column 1 or 2. The search criteria may not necessarily appear in the beginning of the dropdown items, it may appear anywhere in the text. For example I have a dropdown with 2 columns with first column having "Project Engineer" and second "VAC-1001". My user types "1001" as search criteria and system brings one record, but that record (RadComboBoxItem) is not being selected.

I have set MarkFirstMatch property to "true". I tried setting SelectedItem to its text but getting below error:

"Property 'SelectedItem' is 'ReadOnly'."

I also tried using SelectedIndex, but that is also not working. Please help me select the first item. I am using 2010.2.713.35 verion of Telerik.Web.UI and Telerik.Web.Design.

If RadComboBox.Items.Count > 0 Then
 RadComboVacancyList.SelectedIndex = 0
End
If

Many thanks.
Boyan Dimitrov
Telerik team
 answered on 04 Mar 2013
3 answers
212 views
I've got a column with telephone numbers, some with extensions, entered via a RadMaskedTextBox with Mask="(###) ###-#### ####".  Is it possible to have a DataFormatString which shows the entries properly? DataFormatString="{0:(###) ###-#### ####}" shifts everything to the right for numbers with no extensions.
Eyup
Telerik team
 answered on 04 Mar 2013
8 answers
144 views
I'm looking for a way to validate the Rooms drop down on the Advanced form. I want to required that a room has to be selected when creating the appointment and then show an indicator as to which field is required. Can this be done with the scheduler control?
Plamen
Telerik team
 answered on 04 Mar 2013
1 answer
103 views
Not only did I have issues with the controls not registering themselves within VS (http://www.telerik.com/community/forums/aspnet-ajax/general-discussions/radcontrols-for-asp-net-ajax-upgrade-wizard-fails.aspx), but features in the Grid are buggy. 

I have validated this on 2 different machines running VS2010.  I can add a RadGrid into the page with no issue.  When I go into the properties window to edit settings in the MasterTableView area, VS just crashes with the error "Visual Studio has encountered an error".  

Both machines are running Win7 x64, with up to date patches.  

This has to be the most buggy release I have seen from Telerik in some time.  
Andrey
Telerik team
 answered on 04 Mar 2013
1 answer
69 views
I need to bind a dropdown list depending on what is selected in another dropdown. I know i need to attach a selectedindexchanged event to the first dropdown but i am unsure on how to reference the second the dropdown to rebind within the selectedindexchanged event. Any help would be greatly appreciated.
Shinu
Top achievements
Rank 2
 answered on 04 Mar 2013
1 answer
209 views
Hi.  Would it be possible to modify the "contains" filtering behavior to find any of multiple words in the combobox data?

For example: a combobox item is "follow the yellow brick road".  As I type 'the' then a space and then 'road' it would find this item because it contains any of my filtering words.  The current 'contains' behavior would not have found this item as it would have been looking for 'the road' as one string/keyword.  I hope I am making sense.

Can the client-side events such as itemrequesting or something similar be used to intercept/modify the filter before sent to the data source?

Thank you very much.


-Mike
Dimitar Terziev
Telerik team
 answered on 04 Mar 2013
5 answers
287 views
I use RadGrid contorls , it include a BoundColumn. I set DataFormatString="{0:C}", GridColumn Show is "$10.00", I use RadDataItem["money"].text get value "$10.00",Data origin value is "10", I want get value "10",why do?
Shinu
Top achievements
Rank 2
 answered on 04 Mar 2013
3 answers
122 views
We are running WebForms and MVC apps side by side (in one project) and have RadCompression enablePostbackCompression enabled. This causes a problem in our MVC app, whenever a request returns 500 status code.

The easiest way to reproduce this is to enable postback compression, decorate an action with a HandleError attribute (which returns 500 in case of an unhandled exception), turn custom errors on and throw an exception inside the action. The expected result would be to be redirected to the error page. Instead, we get an encoding error because RadCompression module appends "gzip" to Content-encoding header without checking whether it was already appended, resulting in "Content-encoding: gzip,gzip".

What are my options besides turning off postback compression altogether? Ideally, I'd want to use RadCompressionSettingsAttribute to disable compression for a given action or controller but that hasn't worked. Any thoughts?
Martin
Telerik team
 answered on 04 Mar 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?