Good afternoon, I tried to export a radgrid to Excel with success using
Telerik.Web.UI.GridExcelExportFormat.ExcelML with ExportOnlyData/IgnorePaging/OpenInNewWindow all set to true. I have search for a couple of days a way to add content to the Excel sheet before adding the radgrid. I mean, I need to add some text to the Excel file and execute some macro on the Excel sheet. How can I do this? The radgrid is using Ajax.
Any help would be most appreciated. Shoud a use an Excel template and feed the datagrid into it? By the way, I am using Excel 2007 but hope everything work's also in Excel 2003.
I use the function ExcelMLExportRowCreated and ExcelMLExportStylesCreated to format the loook and feel of the columns with success.
Thank's for your precious time :)
Mario
Hi,
I am using RadCombobox with EnableLoadOnDemand="true" Option , its working fine.I have Clear Button in the same page ,After clicking on Clear Button i need to display default item in combobox.
I saw solution for the same requirement , but thats not working .
Following is Aspx Code :
<telerik:RadComboBox ID="RadComboBox1" runat="server"
EmptyMessage="Select" EnableLoadOnDemand="true"
>
</telerik:RadComboBox>
<asp:Button ID="btnSubmit" runat ="server" Text ="Clear" OnClick ="btnSubmit_click"/>
Following is Csharp Code :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dataTable = CreateDataSource();
foreach (DataRow dataRow in dataTable.Rows)
{
RadComboBoxItem item = new RadComboBoxItem();
item.Text = (string)dataRow["Name"];
item.Value = dataRow["ID"].ToString();
RadComboBox1.Items.Add(item);
item.DataBind();
}
// preselect the second item
//RadComboBox1.SelectedValue = "0";
RadComboBox1.Items[0].Selected = true;
}
}
protected DataTable CreateDataSource()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
DataRow dr = dataTable.NewRow();
dr["ID"] = "0";
dr["Name"] = "SELECT NAME";
dataTable.Rows.Add(dr);
DataRow dr1 = dataTable.NewRow();
dr1["ID"] = "1";
dr1["Name"] = "Name1";
dataTable.Rows.Add(dr1);
DataRow dr2 = dataTable.NewRow();
dr2["ID"] = "2";
dr2["Name"] = "Name2";
dataTable.Rows.Add(dr2);
DataRow dr3 = dataTable.NewRow();
dr3["ID"] = "3";
dr3["Name"] = "Name3";
dataTable.Rows.Add(dr3);
return dataTable;
}
protected void btnSubmit_click(object sender, EventArgs e)
{
RadComboBox1.Items[0].Selected = true;
}
}
Thanks,
<style type="text/css">
.AutoShrink
{
width: auto !important;
max-width:1350px;
}
div.AutoShrink
{
float: left;
}
</style>
<telerik:RadGrid ID="grdResult" runat="server"
AllowMultiRowSelection="True" AllowSorting="True" Height="400px" width="1350px"
style="margin-right: 1px" Skin="WebBlue" GridLines="None" AllowPaging="true" PageSize="100"
CssClass="AutoShrink" >
<PagerStyle Position="Top" />
<MasterTableView AllowPaging="true" AutoGenerateColumns="true" AllowMultiColumnSorting="true" ClientDataKeyNames="SRC,SER,BAND,XLA,XLG,RGN,STT,EIP,SVC,FRQ,FTA" Font-Size="Smaller" PageSize="100" TableLayout="Auto" CssClass="AutoShrink" >
<Columns>
<%-- <telerik:GridClientSelectColumn UniqueName="SEL" HeaderText="SEL" ItemStyle-Width="20px" HeaderStyle-Width="20px"></telerik:GridClientSelectColumn>--%>
<telerik:GridTemplateColumn UniqueName="SEL">
<HeaderTemplate>
<asp:CheckBox runat="server" ID="ChkAll" ToolTip="Click to select all" onclick="javascript:SelectAllCheckboxes(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox runat="server" ID="SEL" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings ReorderColumnsOnClient="true" EnableRowHoverStyle="False" AllowColumnsReorder="true" >
<Scrolling AllowScroll="True" />
<Selecting AllowRowSelect="true" />
<Resizing EnableRealTimeResize="true" ResizeGridOnColumnResize="true" AllowColumnResize="true"/>
<ClientEvents OnRowContextMenu="grdResult_RowSelected" OnRowClick="RowClicked" />
</ClientSettings>
<HeaderStyle Width="100px"/>
<PagerStyle Mode="NextPrevAndNumeric" ></PagerStyle>
</telerik:RadGrid>
Thanks,
Raji
I click a menu item and the color after I close and return to the menu item changes to blue. I want it to remain white.
I hate to bring this question to you but I don't understand your RadGrid filtering example and have coded it the best I can. It is a simple example that has a DataTable loaded as the grid datasource on page load. Now the both the ASPX and the ASPX.CS code is below:
ASPX.CS
public partial class AdminSearch : System.Web.UI.Page
{
public static ArrayList LocationArray;
public DataTable myDataTable = new DataTable();
SqlDataSource sqlDS = new SqlDataSource();
protected void Page_Load(object sender, EventArgs e)
{
SearchGrid.DataSource = GetDataTable();
}
public DataTable GetDataTable()
{
myDataTable.Columns.Add(new DataColumn("KMLID", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Remarks", typeof(string)));
myDataTable.Columns.Add(new DataColumn("LONGITUDE", typeof(string)));
myDataTable.Columns.Add(new DataColumn("LATITUDE", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Pax", typeof(string)));
myDataTable.Columns.Add(new DataColumn("StartDate", typeof(string)));
myDataTable.Columns.Add(new DataColumn("EndDate", typeof(string)));
myDataTable.Columns.Add(new DataColumn("Type", typeof(string)));
DataRow workRow;
bool bsuccess = CacheManager.Get<ArrayList>("LocationArray", out LocationArray);
foreach (Marker m in LocationArray)
{
workRow = myDataTable.NewRow();
workRow["KMLID"] = m.KMLID;
workRow["Remarks"] = m.Remarks;
workRow["LONGITUDE"] = m.LONGITUDE;
workRow["LATITUDE"] = m.LATITUDE;
workRow["Pax"] = m.Pax;
workRow["StartDate"] = m.StartDate.ToString();
workRow["EndDate"] = m.EndDate.ToString();
if (m.Type == "Operations")
{
workRow["Type"] = m.Type;
}
else
{
workRow["Type"] = m.Type;
}
myDataTable.Rows.Add(workRow);
}
return myDataTable;
}
protected void SearchGrid_PreRender(object sender, System.EventArgs e)
{
if (SearchGrid.MasterTableView.FilterExpression != string.Empty)
{
SearchGrid.DataSource = GetDataTable();
}
}
protected void SearchGrid_ItemCommand(object source, GridCommandEventArgs e)
{
myDataTable.Clear();
if (e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
switch (filterPair.Second.ToString())
{
case "StartDate":
this.startDate = ((e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("StartDatePicker") as RadDatePicker).SelectedDate;
this.endDate = ((e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("StartDatePicker") as RadDatePicker).SelectedDate;
break;
default:
break;
}
}
}
protected DateTime? SetStartDate(GridItem item)
{
if (item.OwnerTableView.GetColumn("StartDate").CurrentFilterValue == string.Empty)
{
return new DateTime?();
}
else
{
return DateTime.Parse(item.OwnerTableView.GetColumn("StartDate").CurrentFilterValue);
}
}
protected DateTime? startDate
{
set
{
ViewState["strD"] = value;
}
get
{
if (ViewState["strD"] != null)
return (DateTime)ViewState["strD"];
else
return new DateTime(2019, 7, 4);
}
}
protected DateTime? endDate
{
set
{
ViewState["endD"] = value;
}
get
{
if (ViewState["endD"] != null)
return (DateTime)ViewState["endD"];
else
return new DateTime(2019, 5, 6);
}
}
}
ASPX
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AdminSearch.aspx.cs" Inherits="COPASPApplication.AdminSearch" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div>
<span style="align-content:end; font-size:12px;"><asp:LinkButton runat="server" PostBackUrl="COPAdminView.aspx">Administrative User Page</asp:LinkButton></span>
<h3>Administrative Search Page</h3>
</div>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
<div class="demo-container no-bg">
<telerik:RadGrid RenderMode="Lightweight" ID="SearchGrid" Width="100%" AllowFilteringByColumn="True"
AllowSorting="True" AllowPaging="True" PageSize="7" runat="server" AutoGenerateColumns="False"
EnableLinqExpressions="false" OnItemCommand="SearchGrid_ItemCommand" ShowStatusBar="true">
<MasterTableView DataKeyNames="KMLID" TableLayout="Fixed">
<Columns>
<telerik:GridBoundColumn DataField="KMLID" HeaderText="KMLID" UniqueName="KMLID"
HeaderStyle-Width="25px" SortExpression="KMLID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Remarks" HeaderText="Remarks" UniqueName="Remarks"
HeaderStyle-Width="100px" SortExpression="Remarks">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LONGITUDE" HeaderText="LONGITUDE" UniqueName="LONGITUDE"
HeaderStyle-Width="80px" SortExpression="LONGITUDE">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LATITUDE" HeaderText="LATITUDE" UniqueName="LATITUDE"
HeaderStyle-Width="80px" SortExpression="LATITUDE">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Pax" HeaderText="Pax" UniqueName="Pax"
HeaderStyle-Width="25px" SortExpression="Pax" >
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="StartDate" DataField="StartDate" HeaderText="Start date"
DataFormatString="{0:D}" HeaderStyle-Width="90px">
<FilterTemplate>
<telerik:RadDatePicker RenderMode="Lightweight" ID="StartDatePicker" runat="server" Width="110px" ClientEvents-OnDateSelected="StartDateSelected"
MinDate="01-01-2019" MaxDate="05-06-2025" FocusedDate="07-04-1996" />
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
function StartDateSelected(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
var startDate = $find('<%# ((GridItem)Container).FindControl("StartDatePicker").ClientID %>');
var startDate = FormatSelectedDate(sender);
tableView.filter("StartDate", startDate, "EqualTo");
}
function FormatSelectedDate(picker) {
var date = picker.get_selectedDate();
var dateInput = picker.get_dateInput();
var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());
return formattedDate;
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="EndDate" DataField="EndDate" HeaderText="EndDate"
DataFormatString="{0:d}" HeaderStyle-Width="80px">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Type" HeaderText="Type" UniqueName="Type"
HeaderStyle-Width="80px" SortExpression="Type">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</asp:Content>
Hello Guys,
Long time TELERIK fan.. but my first Post..
I am banging my head for the past 2 days in figuring out the issue.
Below is my RadGrid for Bulk Edit/Update. All the CRUD operations works with a minor issue.
I have two radcomboboxs "cmbFundingSrc" & "cmbEntityType". When i click the row to edit values..
RadCombobox "cmbFundingSrc" will loose the selected value BUT other RadCombobox "cmbEntityType" will retain & show the existing selected value.
What could be the issue? Kindly let me know
<%@ Register assembly="Telerik.Web.UI, Version=2018.1.117.45, Culture=neutral, PublicKeyToken=121fae78165ba3d4" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<telerik:RadFormDecorator ID="FormDecorator1" runat="server" />
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" RenderMode="Inline">
<asp:Panel runat="server" ID="pnlLineItemFormAdd" >
<br />
<table cellpadding="4" cellspacing="2" border="1" width="100%" style="table-layout:fixed" class="detail-SubTable" >
<tr>
<td>
<telerik:RadGrid ID="rgRegEntity" runat="server" AllowSorting="True" AllowPaging="True"
RenderMode="Lightweight" AllowAutomaticInserts="True" AutoGenerateColumns="False" AllowAutomaticUpdates="True"
DataSourceID="SqlDataSource1" OnItemDeleted="rgRegEntity_ItemDeleted"
AllowAutomaticDeletes="True">
<MasterTableView DataKeyNames="RegistrationFundingSourceUID" ClientDataKeyNames="RegistrationFundingSourceUID"
DataSourceID="SqlDataSource1"
NoMasterRecordsText="No Records to display." Width="100%" TableLayout="Auto" ShowHeadersWhenNoRecords="true"
EditMode="Batch" CommandItemDisplay="TopAndBottom">
<BatchEditingSettings EditType="Row" SaveAllHierarchyLevels="true" OpenEditingEvent="Click"/>
<CommandItemSettings ShowSaveChangesButton="true" ShowCancelChangesButton="true" />
<Columns>
<telerik:GridButtonColumn ConfirmText="Delete this LineItem?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="3%" ItemStyle-Width="50px"
CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="RegistrationUID" HeaderStyle-Width="3%" HeaderText="RegistrationUID" SortExpression="RegistrationUID"
UniqueName="RegistrationUID" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Funding Source <br />[Reporting Category]" HeaderStyle-Width="14%" UniqueName="CPFundingsId" DataField="CPFundingsId">
<ItemTemplate>
<%# Eval("fundingsourcename") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList RenderMode="Lightweight" DefaultMessage="Select Funding Src" runat="server" ID="cmbFundingSrc" DataValueField="CPFundingsId"
DataTextField="fundingsourcename" DataSourceID="SqlFundingDataSource" DropDownWidth="200px" >
</telerik:RadDropDownList>
<span style="color: Red">
<asp:RequiredFieldValidator ID="RequiredFieldValidator12"
ControlToValidate="cmbFundingSrc" ErrorMessage="*Required" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>
</span>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Document <br />Type" HeaderStyle-Width="7%" UniqueName="EntityTypeUID" DataField="EntityTypeUID">
<ItemTemplate>
<%# Eval("EntityType") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList RenderMode="Lightweight" runat="server" DefaultMessage="Select Document Type" ID="cmbEntityType" DataValueField="EntityTypeUID"
DataTextField="EntityType" DataSourceID="SqlEntityTpeMstDataSource" DropDownWidth="200px">
</telerik:RadDropDownList>
<span style="color: Red">
<asp:RequiredFieldValidator ID="RequiredFieldValidator9"
ControlToValidate="cmbEntityType" ErrorMessage="*Required" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>
</span>
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowExpandCollapse="true">
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="True" ScrollHeight="255" UseStaticHeaders="true" />
</ClientSettings>
</telerik:RadGrid>
</td>
</tr>
</table>
<hr id="hrLine" class="line-Style-Separator" />
<div width="100" STYLE="text-align:left;">
<asp:Label runat="server" ID="lblLastModifiedBy" STYLE="text-align:left;" />
</div>
<asp:TextBox runat="server" ID="txtRegID" visible="false"></asp:TextBox>
<asp:TextBox runat="server" ID="txtPrimeContractorID" visible="false"></asp:TextBox>
<asp:TextBox runat="server" ID="txtLoggedInUserID" visible="false"></asp:TextBox>
</asp:Panel>
</telerik:RadAjaxPanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Budget2013ConnectionString %>"
SelectCommand="SELECT
distinct [RegistrationUID]
,[RegistrationFundingSourceUID]
,[CPFundingsId]
,[fundingsourcename]
,[EntityTypeUID]
,[EntityId]
,[EntityType]
,[SecondaryContractor]
FROM vwRegistrationLineltems WHERE (RegistrationUID = @RegistrationUID)"
DeleteCommand="DELETE FROM [tblRegistrationFundingSources] WHERE [RegistrationFundingSourceUID]= @RegistrationFundingSourceUID"
>
<SelectParameters>
<asp:QueryStringParameter Name="RegistrationUID" Type="Int32" QueryStringField="RegistrationUID" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="RegistrationFundingSourceUID" Type="Int32"></asp:Parameter>
</DeleteParameters>
</asp:SqlDataSource>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlEntityTpeMstDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Budget2013ConnectionString %>"
SelectCommand=" SELECT [EntityTypeUID],[EntityType] FROM [Budget2013].[Lookups].[tblEntityTypeMst]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlFundingDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Budget2013ConnectionString %>"
SelectCommand="SELECT DISTINCT [CPFundingsId] ,[fundingsourcename] FROM [Budget2013].[dbo].[vwRegistrationCPListWithFundingInfo] "
>
</asp:SqlDataSource>
<SelectParameters>
<asp:QueryStringParameter Name="RegistrationUID" Type="Int32" QueryStringField="RegistrationUID" />
</SelectParameters>
</asp:SqlDataSource>
I would like to know if it's possible to bind extra values other than DataTextField and DataValueField. I am using SQLDataSource.
Thanks!
Im trying to SAVE the resulting image to the server. Tried following some sample code with no luck
Sever side code never fires
(Code simple passes a MEMORY STREAM object to a function (doc.AddVersion) that will save the content into the database)
Error: Sys.ArgumentException: Cannot deserialize empty string.
Parameter name: data ScriptResource.axd:50457:2736
create
argument
deserialize
_readJson
_finishOperation
createCallback
createDelegate
WebForm_ExecuteCallback
WebForm_CallbackComplete
Protected
Sub
RadImgEdt_ImageSaving(sender
As
Object
, args
As
Telerik.Web.UI.ImageEditorSavingEventArgs)
Dim
doc
As
Object
= tableDocumentGeneric.getDocument()
Dim
img
As
Telerik.Web.UI.ImageEditor.EditableImage = args.Image
Dim
ms
As
New
IO.MemoryStream
img.CopyToStream(ms)
doc.AddVersion(ms)
args.Cancel =
True
End
Sub
<
telerik:RadImageEditor
ID
=
"RadImageEditor1"
runat
=
"server"
OnClientImageLoad
=
"OnClientImageLoad"
OnClientCommandExecuting
=
"OnClientCommandExecuting"
OnImageSaving
=
"RadImgEdt_ImageSaving"
Style
=
"top: 0px; left: 0px;"
Width
=
"100%"
Height
=
"100%"
>
<
EditableImageSettings
MaxJsonLength
=
"2147483640"
/>
<
Tools
>
<
telerik:ImageEditorToolGroup
>
<
telerik:ImageEditorTool
CommandName
=
"Print"
/>
<
telerik:ImageEditorTool
CommandName
=
"Save"
/>
<
telerik:ImageEditorTool
CommandName
=
"Crop"
/>
<
telerik:ImageEditorTool
CommandName
=
"Zoom"
/>
<
telerik:ImageEditorToolStrip
Text
=
"Undo"
CommandName
=
"Undo"
/>
<
telerik:ImageEditorToolStrip
Text
=
"Redo"
CommandName
=
"Redo"
/>
<
telerik:ImageEditorTool
Text
=
"Rotate Right"
CommandName
=
"RotateRight"
/>
<
telerik:ImageEditorTool
Text
=
"Rotate Left"
CommandName
=
"RotateLeft"
/>
<
telerik:ImageEditorTool
Text
=
"Reset"
CommandName
=
"Reset"
/>
</
telerik:ImageEditorToolGroup
>
</
Tools
>
</
telerik:RadImageEditor
>
<
script
>
(function (global, undefined) {
Telerik.Web.UI.ImageEditor.CommandList["Print"] = function (imgEditor, commandName, args) {
printIT();
};
})(window);
function printIT() {
//redirect to show PDF version of item
}
function OnClientImageLoad(imageEditor, args) {
imgEditor = imageEditor;
imgEditor.set_height(document.body.scrollHeight - 50);
imageEditor.zoomBestFit();
}
//SAVE
function OnClientCommandExecuting(imageEditor, eventArgs) {
if (eventArgs.get_commandName() == 'Save') {
console.log(eventArgs);
imageEditor.saveImageOnServer('', true);
//Prevent the buil-in Save dialog to pop up
imageEditor.setToggleState('Save', false);
imageEditor.saveImageOnServer('', true);
eventArgs.set_cancel(true);
}
}
</
script
>