I recently used Telerik reports, and i got into a problem where report viewer cached the previous versions other than refreshing the report.
I followed the sample in below link from telerik in order to generate my report.
http://www.telerik.com/help/reporting/mvc-report-viewer-extension-embedding.html
below is the code from my report viewer.
@(Html.TelerikReporting().ReportViewer()
.Id("reportViewer1")
.ServiceUrl("/api/reports/")
.TemplateUrl("/Content/ReportViewer/templates/telerikReportViewerTemplate.html")
.ReportSource(new TypeReportSource() { TypeName = "MvcReportApplication.MyReport.Report5, MvcReportApplication" })
.ViewMode(ViewModes.INTERACTIVE)
.ScaleMode(ScaleModes.SPECIFIC)
.Scale(1.0)
.PersistSession(true)
)
To disable the report viewer caching just change PersistSession(true) to PersistSession(false) and you are good to go.
Showing posts with label Telerik. Show all posts
Showing posts with label Telerik. Show all posts
Tuesday, November 19, 2013
Friday, February 8, 2013
How to Get RadGrid Filtered DataSource

Below method will return the data source of the RadGrid after you have applied filters to the grid. We have assigned the current filter expression of the RadGrid to a string and then filter the DataTable by passing the filter expression.
First add the reference to the dynamic linq library. Download the dynamic linq library here. Add the following reference.
First add the reference to the dynamic linq library. Download the dynamic linq library here. Add the following reference.
using System.Linq.Dynamic;
private DataTable GetFilteredDataSource()
{
DataTable DT = new DataTable();
DataTable FilteredDT = new DataTable();
string filterexpression = string.Empty;
filterexpression = RadGrid1.MasterTableView.FilterExpression;
DT = (DataTable)RadGrid1.DataSource;
FilteredDT = DT.AsEnumerable()
.AsQueryable()
.Where(filterexpression)
.CopyToDataTable();
return FilteredDT;
}
Wednesday, February 6, 2013
Show Popup Window On RadGrid Link Button Click

This example demonstrate how to show a popup window on a link buttin click inside Telerik RadGrid. Our RadGrid mark up code looks like below.
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
An example preview would be as follows:

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">Code behind:
<Windows>
<telerik:RadWindow ID="RadWindow1" runat="server" ShowContentDuringLoad="false" Width="400px"
Height="400px" Title="Record Data" Behaviors="Default">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
<div style="width: 840px; overflow: auto">
<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" Width="600px"
Skin="Hay" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True"
CellSpacing="0" onitemcreated="RadGrid1_ItemCreated" PageSize="30">
<MasterTableView IsFilterItemExpanded="true" TableLayout="Auto">
<Columns>
<telerik:GridTemplateColumn UniqueName="Data" HeaderText="View Data" AllowFiltering="false">
<ItemTemplate>
<asp:HyperLink ID="hlink" runat="server" Text="View"></asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</telerik:RadGrid>
</div>
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)}
{HyperLink photoLink = (HyperLink)e.Item.FindControl("hlink");}
photoLink.Attributes.Add("Onclick", " return radopen('ShowData.aspx','RadWindow1');");
An example preview would be as follows:

Friday, February 1, 2013
Simple Telerik RadGrid Databind

Below is the .aspx mark up code of the RadGrid with six columns.
You can generate you'r own data source and bind it to the RadGrid.
protected void Page_Load(object sender, EventArgs e)
{
private void GetActivityLog()
{
protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" Width="600"
Skin="Vista" AllowPaging="True" AllowSorting="True"
onpageindexchanged="RadGrid1_PageIndexChanged"
onpagesizechanged="RadGrid1_PageSizeChanged" CellSpacing="0"
GridLines="None" >
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="Project"
FilterControlAltText="Filter UserName column" HeaderText="Project"
UniqueName="Project">
<ItemStyle Width="200px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Mode"
FilterControlAltText="Filter Mode column" HeaderText="Mode"
UniqueName="Mode">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Activity"
FilterControlAltText="Filter Activity column" HeaderText="Activity"
UniqueName="Activity">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PageURL"
FilterControlAltText="Filter PageUrl column" HeaderText="Page Url"
UniqueName="PageURL">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ActDate" DataType="System.DateTime"
FilterControlAltText="Filter ActDate column" HeaderText="Activity Date"
UniqueName="ActivityDate">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="UserName"
FilterControlAltText="Filter UserName column" HeaderText="User Name"
UniqueName="UserName">
</telerik:GridBoundColumn>
</Columns>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Vista"></HeaderContextMenu>
</telerik:RadGrid>
You can generate you'r own data source and bind it to the RadGrid.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)}
{GetActivityLog();}
private void GetActivityLog()
{
RadGrid1.MasterTableView.DataSource = BasePage.GetActivityLog();//bind //your own data source here}
RadGrid1.DataBind();
protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
GetActivityLog();}
protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
GetActivityLog();}
Thursday, January 24, 2013
Accessing DataKeys in Telerik RadGrid

Let's assume that we have a RadGrid with a bind DataTable which contains the columns "ConnectionString" and "HDSite". To add the Column names to the Datakeys we can use a code something like below.
<telerik:RadGrid ID="gridSearchL3" runat="server" >
<mastertableview DataKeyNames="ConnectionString,HDSite">
<Columns>
<telerik:GridButtonColumn CommandName="Select" Text="View" UniqueName="LinkColumn" ItemStyle-Width="40" HeaderStyle-Width="40">
</telerik:GridButtonColumn>
</Columns>
</telerik:RadGrid>
To access the DataKeys of each record use the below code.
foreach (GridDataItem item in gridSearchL3.MasterTableView.Items)
{string conStr = item.GetDataKeyValue("ConnectionString").ToString();}
string HSite = item.GetDataKeyValue("HDSite").ToString();
Wednesday, January 16, 2013
How to add Postback control inside RadAjaxPanel

.aspx code
<telerik:RadScriptManager ID="ScriptManager" runat="server" AsyncPostBackTimeout="36000">
</telerik:RadScriptManager>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
</telerik:RadAjaxPanel >
To convert the "Button1" into a post back control add the below code in the page load event.
.cs code
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterPostBackControl(mngBtnExcel);
}
Thursday, January 3, 2013
How to Clear RadGrid Filters

If you have auto generated columns in the RadGrid use the below code.
foreach (GridColumn column in gridSearchL3.MasterTableView.AutoGeneratedColumns)
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue = string.Empty;
}
gridSearchL3.MasterTableView.FilterExpression = string.Empty;
If the columns are not auto generated use the below code.
foreach (GridColumn column in gridSearchL3.MasterTableView.OwnerGrid.Columns)
foreach (GridColumn column in gridSearchL3.MasterTableView.AutoGeneratedColumns)
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue = string.Empty;
}
gridSearchL3.MasterTableView.FilterExpression = string.Empty;
If the columns are not auto generated use the below code.
foreach (GridColumn column in gridSearchL3.MasterTableView.OwnerGrid.Columns)
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue = string.Empty;
}
gridSearchL3.MasterTableView.FilterExpression = string.Empty;
Wednesday, December 19, 2012
Grouping in RadGrid

In this post i'm assuming that you have already done the data binding to the RadGrid. Once you have done the data binding part now you are able to perform the grouping operation on the RadGrid as shown above.
private void GroupRadGrrid()
{
try
{
string expr = "DocHeaderType [Module: ] Group By DocHeaderType";
GridGroupByExpression expression1 = GridGroupByExpression.Parse(expr);
this.RadGrid1.MasterTableView.GroupByExpressions.Add(expression1);
}
catch (Exception ex)
{
throw ex;
}
finally
{
RadGrid1.Rebind();
}
}
You'll have to use the below name space.
using Telerik.Web.UI.GridExcelBuilder;
string expr = "DocHeaderType [Module: ] Group By DocHeaderType";
This is the grouping expression
DocHeaderType - The Radgrid group column
[Module: ] - Alias
Monday, December 17, 2012
Check Column Exists in RadGrid

When using the telerik RadGrid, imagine you want to bind data dynamically and hide some necessary columns from the grid.
When your are trying to hide the column you need to check whether the column exists first. Other wise Radgrid will throw the exception "Telerik.Web.UI.GridException: Cannot find a column with UniqueName 'YourColumn'".
This error occurs if you use the below code to find a column in the RadGrid
RadGrid1.MasterTableView.GetColumn("YourColumn")
To avoid the exception use the below code.
GridColumn g3 = (GridColumn)gridSearchL3.MasterTableView.Columns.FindByUniqueNameSafe("YourColumn");
if (g3 != null)
g3.Visible = false;
This will not throw the exception and returns null if the column was not found.
When your are trying to hide the column you need to check whether the column exists first. Other wise Radgrid will throw the exception "Telerik.Web.UI.GridException: Cannot find a column with UniqueName 'YourColumn'".
This error occurs if you use the below code to find a column in the RadGrid
RadGrid1.MasterTableView.GetColumn("YourColumn")
To avoid the exception use the below code.
GridColumn g3 = (GridColumn)gridSearchL3.MasterTableView.Columns.FindByUniqueNameSafe("YourColumn");
if (g3 != null)
g3.Visible = false;
This will not throw the exception and returns null if the column was not found.
Tuesday, December 11, 2012
Removing RadGrid Filter Menu Items


RadGrid filters consist of number of filtering options but we might not need all of those options to be available. Below code on RadGrid Init event will only retain the specified filtering options.
protected void RadGrid1_Init(object sender, EventArgs e)
{
GridFilterMenu menu = RadGrid2.FilterMenu;
int i = 0;
while (i < menu.Items.Count)
{
if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "Contains" || menu.Items[i].Text == "EqualTo")
{
i++;
}
else
{
menu.Items.RemoveAt(i);
}
}
}
Subscribe to:
Posts (Atom)