This is a migrated thread and some comments may be shown as answers.

why radgrid disappeared when using custom datasource from code behind?

7 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
khaled jendi
Top achievements
Rank 1
khaled jendi asked on 21 Aug 2011, 06:58 AM
hi,

I was following this example here: http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultvb.aspx
the only difference is that I am binding data source from code behind in page_load method, means instead of:
 <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" .......
I am using binding in page_load like this:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        dsClients = clsDB.getData(strSQL)
        RadGrid1.DataSource = dsClients
        RadGrid1.DataBind()
        End If
    End Sub





please note that I am using master page and aspx page, in master page I put rad script manager like this:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" AsyncPostBackTimeout="10000" />

and in aspx page I put the ajax panel and rad grid like this:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="onRequestStart" />
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

                                    <telerik:RadGrid ID="RadGrid1" AllowSorting="True"
        AllowPaging="True" PageSize="5" runat="server" GridLines="None" Width="95%"
        OnItemCommand="RadGrid1_ItemCommand">
        <ExportSettings HideStructureColumns="true" />
                <MasterTableView Width="100%" CommandItemDisplay="Top">
            <PagerStyle Mode="NextPrevNumericAndAdvanced" />
            <CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true"
                ShowExportToCsvButton="true" />
        </MasterTableView>
        </telerik:RadGrid>


so when I click any button in the grid its disappeared!

any help?

7 Answers, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 22 Aug 2011, 03:58 AM
Hi Khaled,

Frm the provided code I can see that you are using simple data-binding for the grid. However exporting is not supported with it. I suggest that you bind the grid through its NeedDataSource event instead. Find more information below:
http://www.telerik.com/help/aspnet-ajax/grid-simple-data-binding.html
http://www.telerik.com/help/aspnet-ajax/grid-advanced-data-binding.html

Additionally, note that you should disable ajax upon export, as for the export to work properly, a regular postback is required.

Regards,
Iana
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
khaled jendi
Top achievements
Rank 1
answered on 22 Aug 2011, 11:50 AM
thank you this works,
but when I save the file, I got its name something looks like: RadGridExport.csv

how to change file the file name?
0
Iana Tsolova
Telerik team
answered on 22 Aug 2011, 12:04 PM
Hi Khaled,

Try setting the predefined name in the grid ExportSettings as below:
<telerik:RadGrid ID="RadGrid1" runat="server">
    <ExportSettings FileName="Myreport" />


All the best,
Iana
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
khaled jendi
Top achievements
Rank 1
answered on 23 Aug 2011, 06:17 AM
thank you very much

this works with me for csv, word, and excel, but not pdf, the file name still same on pdf
0
Shinu
Top achievements
Rank 2
answered on 23 Aug 2011, 06:47 AM
Hello Khaled,

Try setting OpenInNewWindow to true to get the same Filename in pdf.
<ExportSettings FileName="Myreport" OpenInNewWindow="true">
</ExportSettings>

Thanks,
Shinu.
0
khaled jendi
Top achievements
Rank 1
answered on 23 Aug 2011, 12:13 PM
hi,

OpenInNewWindow="true" is not working for me !

still I got file name RadGridExport.pdf
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Aug 2011, 12:18 PM
Hello,
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
                e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName ||
e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName)
            {
                ConfigureExport();
            }
        }
       
        public void ConfigureExport()
        {
            RadGrid1.ExportSettings.FileName = "YourFileName";
  
            RadGrid1.ExportSettings.OpenInNewWindow = true;
        }

try with above code snippet and let me know its working or not.

If it is not working then please provide some part of your code.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
khaled jendi
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
khaled jendi
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or