Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
345 views
Hi,

I have a radGrid to which I am trying to export using standard radGrid export options. But I am have few issues as below:

1) Export to CSV is not giving me data.
2) Export to Excel is giving data with extra columns.
3) Export to PDF is giving data with extra columns.

I am using the following code to do the same. Please let me know what the issue is.

ExportRadGrid.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportRadGrid.aspx.cs" Inherits="ExportRadGrid" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <telerik:RadScriptManager ID="scrip" runat="server"></telerik:RadScriptManager>
     <telerik:RadGrid ID="radGrid" runat="server" AutoGenerateColumns="false" AllowPaging="true"
                AllowSorting="true" AllowCustomPaging="true" PageSize="5" AllowFilteringByColumn="true"
               Skin="Office2007">
                <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" />
               
            </telerik:RadGrid>
            
            <asp:Button ID="btnCSV" Text="CSV" runat="server" OnClick="btnCSV_Click"/>
            <asp:Button ID="btnExcel" Text="Excel" runat="server" OnClick="btnExcel_Click"/>
            <asp:Button ID="btnPDF" Text="PDF" runat="server" OnClick="btnPDF_Click"/>
    </div>
    </form>
</body>
</html>


ExportRadGrid.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Telerik.Web.UI;

public partial class ExportRadGrid : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         GridTemplateColumn column1 = new GridTemplateColumn();
            column1.UniqueName = "RollNo";
            column1.HeaderText = "RollNo";
            column1.ItemTemplate = new LabelTemplate("RollNo", string.Empty);

            GridTemplateColumn column2 = new GridTemplateColumn();
            column2.UniqueName = "Name";
            column2.HeaderText = "Name";
            column2.ItemTemplate = new LabelTemplate("Name", string.Empty);

            GridTemplateColumn column3 = new GridTemplateColumn();
            column3.UniqueName = "Address";
            column3.HeaderText = "Address";
            column3.ItemTemplate = new LabelTemplate("Address", string.Empty);


            radGrid.MasterTableView.Columns.Add(column1);
            radGrid.MasterTableView.Columns.Add(column2);
            radGrid.MasterTableView.Columns.Add(column3);

            radGrid.DataSource = GetDataTable();
            radGrid.DataBind();
        
    }

    protected void btnCSV_Click(object sender, EventArgs e)
    {
        SetReportSettings();
        radGrid.MasterTableView.ExportToCSV();
    }
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        SetReportSettings();
        radGrid.MasterTableView.ExportToExcel();
    }
    protected void btnPDF_Click(object sender, EventArgs e)
    {
        SetReportSettings();
        radGrid.MasterTableView.ExportToPdf();
    }

    private void SetReportSettings()
    {
        this.radGrid.ExportSettings.ExportOnlyData = true;
        this.radGrid.ExportSettings.IgnorePaging = true;
        this.radGrid.ExportSettings.OpenInNewWindow = true;
    }

    private DataTable GetDataTable()
    {
        DataTable dt = new DataTable("MyTable");
        dt.Columns.Add("RollNo");
        dt.Columns.Add("Name");
        dt.Columns.Add("Address");

        DataRow dr1 = dt.NewRow();
        dr1["RollNo"] = 1;
        dr1["Name"] = "Mahesh";
        dr1["Address"] = "Addr1";


        DataRow dr2 = dt.NewRow();
        dr2["RollNo"] = 1;
        dr2["Name"] = "Kishore";
        dr2["Address"] = "Addr2";


        DataRow dr3 = dt.NewRow();
        dr3["RollNo"] = 1;
        dr3["Name"] = "Rajesh";
        dr3["Address"] = "Addr3";

        dt.Rows.Add(dr1);
        dt.Rows.Add(dr2);
        dt.Rows.Add(dr3);

        return dt;



    }
}

public class LabelTemplate : ITemplate
{
    public string DataField { get; set; }
    public string DataFormat { get; set; }

    private LabelTemplate()
    {
    }

    public LabelTemplate(string dataField, string dataFormat)
    {
        DataField = dataField;
        DataFormat = dataFormat;
    }

    #region ITemplate Members

    public void InstantiateIn(Control container)
    {
        Label label = new Label();
        label.DataBinding += new EventHandler(Label_DataBinding);
        container.Controls.Add(label);
    }

    void Label_DataBinding(object sender, EventArgs e)
    {
        Label label = (Label)sender;
        GridDataItem container = (GridDataItem)label.NamingContainer;
        if (DataFormat != string.Empty)
            label.Text = string.Format(DataFormat, ((DataRowView)container.DataItem)[DataField].ToString());
        else
            label.Text = ((DataRowView)container.DataItem)[DataField].ToString();
    }

    #endregion
}



Thanks,
Mahesh


Daniel
Telerik team
 answered on 18 Oct 2011
1 answer
62 views
Hello,

I have a radmenu in aspx page and i am adding radsitemap dynamically to radmenuitem.
I am adding radsitemapnodes to radsitemap.
I am using IE9, if i run my application in compatible mode then it works fine.
OR
If i add <meta http-equiv="X-UA-Compatible" content="IE=8" />  in the HEAD section then also it works fine.
In the above two scenarios i was able to see radsitemapnodes with bullets on the left side.
But, if i open my application in normal mode in IE9,then whenever i hover on the menuitem i can see the text of the radsitemapnodes but
the bullets are invisible.
if i click on the menu or if i do some click action on the menu then all bullets are visible .From then i was able to see the bullets in the
Radsitemap.

Does anybody aware of this issue.
Is this the issue with IE9?
Is there any workaround for this?

Please assist.

Thanks,
LV
Peter
Telerik team
 answered on 18 Oct 2011
1 answer
108 views
I'm using a radmenu next to a radcombobox to dynamically show a menu depending on the selected value of the ComboBox using a webservice.

So far so good, except that it looks horrible when I have a multiline menu item.  

The hover over image adds 3 lines to each item and I can't remove it.  

It would be ideal to add an item template to each menu item inside of the webservice, but I can't find any propery of the radmenuitemdata object that accepts a template.

Please help.
Kate
Telerik team
 answered on 18 Oct 2011
1 answer
121 views
Hi,

how to disable text box when i am using rasnUploadCompanyLogo.Enabled = false;

Button and text box  get disable but user still can write some text which is wrong.

Suggest please, How i will stop to write if it is disable.

Thanks ,
Reyaz


Please look the following url:
http://www.telerik.com/community/forums/aspnet-ajax/upload/how-to-disable-focus-from-textbox-in-radupload.aspx
Peter Filipov
Telerik team
 answered on 18 Oct 2011
7 answers
527 views
Hi,

I am having problem in disabling the focus from the textbox of this RadUpload Control. We got this as a usuability bug from our test team. Can anyone help?

Thanks,

Sharad
Peter Filipov
Telerik team
 answered on 18 Oct 2011
2 answers
176 views
Hi,

I am opening a rad window from javascript but it opens with parent page reload.

 function OpenAddNewDocument() {
            window.radopen("AddNewDocument.aspx", "rwAddNewDocument");
            return false;
        }


<input id="btnAddDoc" type="button" value="Add New Document" class="btnAddDoc" title="Add New Document" runat="server"
           onClick="return OpenAddNewDocument();" />


Please help to open this window without postback.


Thanks
Manish.
Manish
Top achievements
Rank 2
 answered on 18 Oct 2011
2 answers
236 views
I have the following RadGrid:

<telerik:RadGrid ID="uxFacilityUsage" runat="server" AllowSorting="True"
        AutoGenerateColumns="False" GridLines="None"
        onneeddatasource="uxFacilityUsage_NeedDataSource" ShowGroupPanel="True"
        onitemdatabound="uxFacilityUsage_ItemDataBound"
        onitemcommand="uxFacilityUsage_ItemCommand" AllowPaging="True"
        PageSize="20" AllowFilteringByColumn="True"
        ongroupschanging="uxFacilityUsage_GroupsChanging">
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
<GroupPanel Text="Drag a column header and drop it here to group by that column."></GroupPanel>
 
<AlternatingItemStyle CssClass="AlternatingRowStyle"></AlternatingItemStyle>
 
<PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
<ExportSettings>
    <Pdf PageLeftMargin="0.5in" PageRightMargin="0.5in" />
</ExportSettings>
<MasterTableView CommandItemDisplay="Top" IsFilterItemExpanded="false">
 
<SortExpressions>
                <telerik:GridSortExpression FieldName="StartDate" SortOrder="Descending" />
            </SortExpressions>
<CommandItemSettings ExportToPdfText="Export to Pdf" ShowAddNewRecordButton="False"
        ShowExportToPdfButton="True"></CommandItemSettings>
<GroupByExpressions>
<telerik:GridGroupByExpression>
    <SelectFields>
        <telerik:GridGroupByField FieldName="CylinderType" Aggregate="Count"/>
    </SelectFields>
    <GroupByFields>
        <telerik:GridGroupByField FieldName="CylinderType" FormatString="{0:0}"/>
    </GroupByFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn DataField="LotNumber"
            FilterControlAltText="Filter LotNumber column" HeaderText="LotNumber"
            SortExpression="LotNumber" UniqueName="LotNumber">
            <HeaderStyle Width="150px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="CylinderType"
            FilterControlAltText="Filter CylinderType column" HeaderText="Cylinder Type"
            SortExpression="CylinderType" UniqueName="CylinderType">
            <HeaderStyle Width="100px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="GasType"
            FilterControlAltText="Filter GasType column" HeaderText="Gas Type"
            SortExpression="GasType" UniqueName="GasType">
            <HeaderStyle Width="100px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Facility"
            FilterControlAltText="Filter Facility column" HeaderText="Facility"
            SortExpression="Facility" UniqueName="Facility" Visible="False">           
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="StartDate"
            DataType="System.DateTime"
            FilterControlAltText="Filter StartDate column"
            HeaderText="Start Date" SortExpression="StartDate"
            UniqueName="StartDate">
            <HeaderStyle Width="150px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="PatientName"
            FilterControlAltText="Filter PatientName column" HeaderText="Patient"
            ReadOnly="True" SortExpression="PatientName" UniqueName="PatientName">
            <HeaderStyle Width="120px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="PayerType"
            FilterControlAltText="Filter PatientName column" HeaderText="Payer Type"
            ReadOnly="True" SortExpression="PayerType" UniqueName="PayerType">
            <HeaderStyle Width="100px" />
        </telerik:GridBoundColumn>         
        <telerik:GridBoundColumn DataField="RoomNumber"
            FilterControlAltText="Filter RoomNumber column" HeaderText="Room"
            SortExpression="RoomNumber" UniqueName="RoomNumber">
            <HeaderStyle Width="50px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="BedAssignment"
            FilterControlAltText="Filter BedAssignment column" HeaderText="Bed"
            SortExpression="BedAssignment" UniqueName="BedAssignment">
            <HeaderStyle Width="100px" />
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Location"
            FilterControlAltText="Filter Location column" HeaderText="Location"
            SortExpression="Location" UniqueName="Location">
            <HeaderStyle Width="150px" />
        </telerik:GridBoundColumn>      
        <telerik:GridBoundColumn DataField="FacilityUsername"
            FilterControlAltText="Filter FacilityUsername column"
            HeaderText="Assigned By" ReadOnly="True" SortExpression="FacilityUsername"
            UniqueName="FacilityUsername">
        </telerik:GridBoundColumn>
    </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<GroupingSettings ShowUnGroupButton="True"></GroupingSettings>
 
        <ClientSettings AllowDragToGroup="True">
 
<Resizing AllowColumnResize="True" EnableRealTimeResize="True"></Resizing>
        </ClientSettings>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
     
    </telerik:RadGrid>

And my NeedDataSource:

using (var context = new DataContext(SqlHelper.NewConnection))
{
    var results = context.ReportCylinderFacilityUsage(Master.FacilitySelection.SelectedValue);
     uxFacilityUsage.DataSource = results.ToList();
}

ReportCylinderFacilityUsage is a stored procedure.  One of the columns it returns is CylinderType

What I'd like to do is group by CylinderType and have the Count for each type of Cylinder displayed in the header.

When I have the following set up in the GroupBy Expressions:
<telerik:GridGroupByExpression>
    <SelectFields>
        <telerik:GridGroupByField FieldName="CylinderType" />
    </SelectFields>
    <GroupByFields>
        <telerik:GridGroupByField FieldName="CylinderType" Aggregate="Count" />
    </GroupByFields>
</telerik:GridGroupByExpression>
I get an error: FieldName contains invalid characters: count(CylinderType)

if I put the Aggregate on the SelectField then I get the error: A column named "CylinderType" already belongs to this datatable.


Thanks,

Jason
Radoslav
Telerik team
 answered on 18 Oct 2011
1 answer
68 views
Hello ,

is it possible to drag and drop from a tree view in a page to another tree view  within a user control ?
same user control will be added multiple times , dynamically .
the main idea ( the page tree view nodes will be divided among the multiple user controls )

Thank you for your help,
Shinu
Top achievements
Rank 2
 answered on 18 Oct 2011
19 answers
735 views
with q1 2008 release, any easy-ish way to make a panel with rounded corners?
Youri
Top achievements
Rank 1
 answered on 18 Oct 2011
1 answer
89 views
Hi,

I am using rad combobox and i want to do that when any <HTML> tag insert in combobox after that user go to click GO button than it should become HTML. I am able to do it on simple asp text box but not able to do it on combobox.

Code example:

On TextBox :
  <script type="text/javascript">
        //remove space from log text box
function RemoveSpecialSymbols(id) {
            var objid = document.getElementById(id);
            if (objid)
                objid.value = html2entities(objid.value);
        }

        function html2entities(sometext) {
            var re = /[<>]/g
            //    if (sometext.length > 2500)
            //        sometext = sometext.substr(0, 2500);
            return sometext.replace(re, function (m) { return replacechar(m) })
        }

        function replacechar(match) {
            if (match == "<")
                return ""
            else if (match == ">")
                return ""
        }
  </script>
<asp:TextBox ID="txtEmail" runat="server" TabIndex="1" MaxLength="50" SkinID="RequiredTextBox" onkeydown="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {RemoveSpecialSymbols(this.id);}};" onblur="RemoveSpecialSymbols(this.id);" ></asp:TextBox>

Same thing i want to do it on RadCombobox....

     <telerik:RadComboBox ID="RCBSearch" runat="server" Width="250px" Height="150px" Text=""
                    ShowToggleImage="false" EmptyMessage="Search by tags, products, business name"
                    EnableLoadOnDemand="true" ShowMoreResultsBox="true" Style="float: left; margin: 0;
                    padding: 0;" EnableVirtualScrolling="true" ShowDropDownOnTextboxClick="false"
                    onkeydown="PressKeyForProfile(this, event)">
                    <WebServiceSettings Method="GetCompanyNames" Path="wsSellWithMe.asmx" />
                </telerik:RadComboBox>


But it is sowing some kind of javascript error...

"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500"

Thanks
Manish
Ivana
Telerik team
 answered on 18 Oct 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?