Hi, I have a problematic situation with a grid bounded to a datasource at runtime.
If I work on the grid only with command buttons by editing then it works by reloading the data with the DataBind method.
If I try to order or change page a javascript exception is thrown:
Exception at row 1, column 123034 in http://localhost:55112/bundles/MsAjaxJs?v=c42ygB2U07n37m_Sfa8ZbLGVu4Rr2gsBo7MvUEnJeZ81
0x800a139e - Javascript run-time error: Sys.WebForms.PageRequestManagerServerErrorException: Index is outside the range. Non-negative value and requires less the size of the collection.
See the attach files for details (is a zip)
Thanks a lot
If I work on the grid only with command buttons by editing then it works by reloading the data with the DataBind method.
If I try to order or change page a javascript exception is thrown:
Exception at row 1, column 123034 in http://localhost:55112/bundles/MsAjaxJs?v=c42ygB2U07n37m_Sfa8ZbLGVu4Rr2gsBo7MvUEnJeZ81
0x800a139e - Javascript run-time error: Sys.WebForms.PageRequestManagerServerErrorException: Index is outside the range. Non-negative value and requires less the size of the collection.
See the attach files for details (is a zip)
Thanks a lot
4 Answers, 1 is accepted
0

Emanuele
Top achievements
Rank 1
Veteran
answered on 02 Mar 2015, 09:23 AM
i've made some tests after reading this advices: http://www.telerik.com/help/aspnet-ajax/grid-most-common-mistakes.html
but nothing has happened, the problem is alive..
here the last code: RichiesteReg.aspx
<%@ Page Title="Rendiconti" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="RichiesteReg.aspx.cs" Inherits="MAV.RichiesteReg" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
asp:Content
ID
=
"HeadContent"
ContentPlaceHolderID
=
"ScriptContent"
runat
=
"server"
>
<
script
type
=
"text/javascript"
src
=
"Scripts/commons.js"
></
script
>
<
script
type
=
"text/javascript"
>
// inizia procedura di salvataggio dati
function Salva() {
//avanti = confirm("Confermi le modifiche?");
avanti = true;
if (avanti) {
avanti = VerificaCampi();
if (avanti) {
return true;
}
else
return false;
}
else
return false;
}
// procedura di verifica della validità dei campi
function VerificaCampi() {
esito = true;
errore = "";
//var sezione = document.getElementById("hidSEZ").value;
var RadDatePickInizio = document.getElementById("ctl00_MainContent_RadDatePickInizio_dateInput");
var RadDatePickFine = document.getElementById("ctl00_MainContent_RadDatePickFine_dateInput");
var txtVarie = document.getElementById("MainContent_txtVarie");
var txtCausale = document.getElementById("MainContent_txtCausale");
// formato data corretto
if (RadDatePickInizio.value != "gg/mm/aaaa")
esito &= VerificaCampo(RadDatePickInizio, "date", false);
if (RadDatePickFine.value != "gg/mm/aaaa")
esito &= VerificaCampo(RadDatePickFine, "date", false);
if (!esito)
errore = "Formato dei parametri non corretto.";
else
{
// i campi non possono essere tutti nulli
if (txtVarie.value == "" && (RadDatePickInizio.value == "" || RadDatePickInizio.value == "gg/mm/aaaa") && (RadDatePickFine.value == "" || RadDatePickFine.value == "gg/mm/aaaa") && txtCausale.value == "")
{
esito = false;
errore = "Inserire almeno un parametro per la ricerca.";
}
}
//var ddlTipoContratto = document.getElementById("ddlTipoContratto");
//errore = "Completare o correggere i dati";
if (!esito) {
document.getElementById("MainContent_lblErrore").innerHTML = errore;
}
return esito;
}
</
script
>
</
asp:Content
>
<
asp:Content
ID
=
"BodyContent"
ContentPlaceHolderID
=
"MainContent"
runat
=
"server"
>
<
telerik:RadAjaxManager
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"rgRichieste"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"rgRichieste"
UpdatePanelCssClass
=
""
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
h2
>Richieste registrazione Rosetta Stone</
h2
>
<
asp:Panel
ID
=
"pnlComandi"
runat
=
"server"
HorizontalAlign
=
"Right"
CssClass
=
"pnlComandi"
Visible
=
"False"
>
</
asp:Panel
>
<
asp:Panel
ID
=
"pnlRicerca"
runat
=
"server"
CssClass
=
"form-inline"
Visible
=
"False"
>
<%--<
fieldset
>--%>
<
div
class
=
"form-group"
>
<
asp:Label
runat
=
"server"
AssociatedControlID
=
"txtVarie"
CssClass
=
"control-label"
>Nominativo/Codice fiscale/Matricola</
asp:Label
>
<
div
style
=
"padding-left:0px;"
> <%--class="col-sm-4"--%>
<
asp:TextBox
runat
=
"server"
ID
=
"txtVarie"
CssClass
=
"form-control"
placeholder
=
""
MaxLength
=
"65"
/>
</
div
>
</
div
>
<
div
class
=
"form-group leftSpace"
>
<
asp:Label
runat
=
"server"
AssociatedControlID
=
"RadDatePickInizio"
CssClass
=
"control-label"
>Data incasso inizio</
asp:Label
><
br
/>
<
telerik:RadDatePicker
ID
=
"RadDatePickInizio"
runat
=
"server"
Calendar-CultureInfo
=
"it-IT"
Calendar-Culture
=
"it-IT"
Skin
=
"Metro"
Calendar-UseRowHeadersAsSelectors
=
"False"
Calendar-ShowRowHeaders
=
"False"
DatePopupButton-ToolTip
=
"Apre il calendario"
>
<
Calendar
Culture
=
"it-IT"
EnableWeekends
=
"True"
FastNavigationNextText
=
"<<"
Skin
=
"Metro"
UseColumnHeadersAsSelectors
=
"False"
UseRowHeadersAsSelectors
=
"False"
CalendarCaption
=
"Calendario"
runat
=
"server"
CultureInfo
=
"it-IT"
>
</
Calendar
>
<
DateInput
DateFormat
=
"dd/MM/yyyy"
DisplayDateFormat
=
"dd/MM/yyyy"
LabelWidth
=
"40%"
CultureInfo
=
"it-IT"
runat
=
"server"
CssClass
=
"form-control di"
EmptyMessage
=
"gg/mm/aaaa"
ID
=
"DataInizio"
EnableAriaSupport
=
"False"
>
<
EmptyMessageStyle
Resize
=
"None"
/>
<
ReadOnlyStyle
Resize
=
"None"
/>
<
FocusedStyle
Resize
=
"None"
/>
<
DisabledStyle
Resize
=
"None"
/>
<
InvalidStyle
Resize
=
"None"
/>
<
HoveredStyle
Resize
=
"None"
/>
<
EnabledStyle
Resize
=
"None"
/>
</
DateInput
>
<
DatePopupButton
HoverImageUrl
=
""
ImageUrl
=
""
ToolTip="<span
class
=
'glyphicon glyphicon-calendar'
></
span
>" runat="server" CssClass="btn btn-default btn-sm" /> <%--rcCalPopup--%>
</
telerik:RadDatePicker
>
</
div
>
<
div
class
=
"form-group leftSpace"
>
<
asp:Label
runat
=
"server"
AssociatedControlID
=
"RadDatePickFine"
CssClass
=
"control-label"
>Data incasso fine</
asp:Label
><
br
/>
<
telerik:RadDatePicker
ID
=
"RadDatePickFine"
runat
=
"server"
Calendar-CultureInfo
=
"it-IT"
Calendar-Culture
=
"it-IT"
Skin
=
"Metro"
Calendar-UseRowHeadersAsSelectors
=
"False"
Calendar-ShowRowHeaders
=
"False"
DatePopupButton-ToolTip
=
"Apre il calendario"
>
<
Calendar
Culture
=
"it-IT"
EnableWeekends
=
"True"
FastNavigationNextText
=
"<<"
Skin
=
"Metro"
UseColumnHeadersAsSelectors
=
"False"
UseRowHeadersAsSelectors
=
"False"
CalendarCaption
=
"Calendario"
runat
=
"server"
CultureInfo
=
"it-IT"
>
</
Calendar
>
<
DateInput
DateFormat
=
"dd/MM/yyyy"
DisplayDateFormat
=
"dd/MM/yyyy"
LabelWidth
=
"40%"
CultureInfo
=
"it-IT"
runat
=
"server"
CssClass
=
"form-control di"
EmptyMessage
=
"gg/mm/aaaa"
>
<
EmptyMessageStyle
Resize
=
"None"
/>
<
ReadOnlyStyle
Resize
=
"None"
/>
<
FocusedStyle
Resize
=
"None"
/>
<
DisabledStyle
Resize
=
"None"
/>
<
InvalidStyle
Resize
=
"None"
/>
<
HoveredStyle
Resize
=
"None"
/>
<
EnabledStyle
Resize
=
"None"
/>
</
DateInput
>
<
DatePopupButton
HoverImageUrl
=
""
ImageUrl
=
""
ToolTip="<span
class
=
'glyphicon glyphicon-calendar'
></
span
>" runat="server" CssClass="btn btn-default btn-sm" /> <%--rcCalPopup--%>
</
telerik:RadDatePicker
>
</
div
>
<
div
class
=
"form-group leftSpace"
>
<
asp:Label
runat
=
"server"
AssociatedControlID
=
"txtCausale"
CssClass
=
"control-label"
>Causale/Disposizione</
asp:Label
>
<
div
style
=
"padding-left:0px;"
> <%--class="col-sm-4"--%>
<
asp:TextBox
runat
=
"server"
ID
=
"txtCausale"
CssClass
=
"form-control"
placeholder
=
""
MaxLength
=
"255"
/>
</
div
>
</
div
>
<%--</
fieldset
>--%>
<
div
class
=
"form-group leftSpace btn-bottom"
>
<%--<
div
class
=
"col-sm-offset-3 col-sm-9"
>--%>
<
asp:LinkButton
ID
=
"btnCerca"
runat
=
"server"
CommandName
=
"Search"
Text
=
"Cerca"
CssClass
=
"btn btn-default btn-sm"
ToolTip
=
"Cerca"
OnClick
=
"btnCerca_Click"
OnClientClick
=
"return Salva();"
></
asp:LinkButton
>
<%--</
div
>--%>
</
div
>
<
div
class
=
"form-group leftSpace btn-bottom"
>
<
asp:LinkButton
ID
=
"btnExport"
runat
=
"server"
CommandName
=
"Export"
Text
=
"Esporta"
CssClass
=
"disabled btn btn-default btn-sm"
ToolTip
=
"esporta i dati"
OnClick
=
"btnExport_Click"
Visible
=
"False"
>
<
span
class
=
"glyphicon glyphicon-export"
></
span
>
</
asp:LinkButton
>
</
div
>
<
asp:PlaceHolder
runat
=
"server"
ID
=
"ErrorMessage"
Visible
=
"true"
>
<
p
class
=
"text-danger"
>
<
asp:Label
runat
=
"server"
ID
=
"lblErrore"
></
asp:Label
>
</
p
>
</
asp:PlaceHolder
>
</
asp:Panel
>
<
telerik:RadGrid
ID
=
"rgRichieste"
runat
=
"server"
CellSpacing
=
"-1"
Culture
=
"it-IT"
GridLines
=
"Both"
GroupPanelPosition
=
"Top"
AllowSorting
=
"True"
DataSourceID
=
"dsMAV"
AutoGenerateColumns
=
"False"
PageSize
=
"10"
OnPreRender
=
"rgRichieste_PreRender"
ShowStatusBar
=
"True"
AllowPaging
=
"True"
Skin
=
"Metro"
MasterTableView-NoMasterRecordsText
=
"Nessun record da visualizzare."
OnItemCommand
=
"rgRichieste_ItemCommand"
OnItemDataBound
=
"rgRichieste_ItemDataBound"
OnNeedDataSource
=
"rgRichieste_NeedDataSource"
>
<
SortingSettings
SortToolTip
=
"Click qui per ordinare"
SortedAscToolTip
=
"ordinato crescente"
SortedDescToolTip
=
"ordinato decrescente"
></
SortingSettings
>
<
ExportSettings
FileName
=
"richieste"
IgnorePaging
=
"True"
ExportOnlyData
=
"True"
OpenInNewWindow
=
"True"
>
<
Pdf
PageWidth
=
""
AllowPrinting
=
"False"
></
Pdf
>
</
ExportSettings
>
<
MasterTableView
DataSourceID
=
"dsMAV"
DataKeyNames
=
"IDRegistrazione"
>
<
RowIndicatorColumn
Visible
=
"False"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Created
=
"True"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"IDRegistrazione"
HeaderText
=
"ID"
SortExpression
=
"IDRegistrazione"
UniqueName
=
"IDRegistrazione"
FilterControlAltText
=
"Filter ID column"
Visible
=
"False"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CF"
HeaderText
=
"CF"
SortExpression
=
"CF"
UniqueName
=
"CF"
FilterControlAltText
=
"Filter CF column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Nome"
HeaderText
=
"Nome"
SortExpression
=
"Nome"
UniqueName
=
"Nome"
FilterControlAltText
=
"Filter Nome column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Cognome"
HeaderText
=
"Cognome"
SortExpression
=
"Cognome"
UniqueName
=
"Cognome"
FilterControlAltText
=
"Filter Cognome column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"EmailUPO"
HeaderText
=
"Email"
SortExpression
=
"EmailUPO"
UniqueName
=
"EmailUPO"
FilterControlAltText
=
"Filter Email column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CodiceRuolo"
HeaderText
=
"Ruolo"
SortExpression
=
"CodiceRuolo"
UniqueName
=
"CodiceRuolo"
FilterControlAltText
=
"Filter Ruolo column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Telefono"
HeaderText
=
"Tel."
SortExpression
=
"Telefono"
UniqueName
=
"Telefono"
FilterControlAltText
=
"Filter Telefono column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DataRichiesta"
HeaderText
=
"DataRichiesta"
SortExpression
=
"DataRichiesta"
UniqueName
=
"DataRichiesta"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter DataRichiesta column"
DataFormatString
=
"{0:dd/MM/yyyy}"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DataAbilitazione"
HeaderText
=
"DataAbilitazione"
SortExpression
=
"DataAbilitazione"
UniqueName
=
"DataAbilitazione"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter DataAbilitazione column"
DataFormatString
=
"{0:dd/MM/yyyy}"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"IDOperatoreAbilitazione"
HeaderText
=
"Operatore"
SortExpression
=
"IDOperatoreAbilitazione"
UniqueName
=
"IDOperatoreAbilitazione"
FilterControlAltText
=
"Filter Operatore column"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
></
ModelErrorMessage
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Azione"
AllowFiltering
=
"false"
UniqueName
=
"Azione"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"btnAbilita"
runat
=
"server"
Text
=
"Abilita"
CssClass
=
"btn btn-default btn-sm"
ToolTip
=
"Abilita"
CommandName
=
"Abilita"
><%-- --%>
<
span
class
=
"glyphicon glyphicon-ok"
></
span
>
</
asp:LinkButton
>
<
asp:LinkButton
ID
=
"btnDisabilita"
runat
=
"server"
Text
=
"Disabilita"
CssClass
=
"btn btn-default btn-sm"
ToolTip
=
"Disabilita"
CommandName
=
"Disabilita"
><%-- --%>
<
span
class
=
"glyphicon glyphicon-remove"
></
span
>
</
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
runat
=
"server"
ID
=
"dsMAV"
ConnectionString='<%$ ConnectionStrings:MAV %>'
SelectCommand=""></
asp:SqlDataSource
>
</
asp:Content
>
RichiesteReg.aspx.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Configuration;
using
System.Data;
using
System.Data.SqlClient;
using
System.Xml;
using
OfficeOpenXml;
using
OfficeOpenXml.Style;
using
System.Drawing;
using
Telerik.Web.UI;
namespace
MAV
{
public
partial
class
RichiesteReg : System.Web.UI.Page
{
// connessione db
protected
string
_connDb;
// numero record
protected
int
_nRec = 0;
// dataview
public
DataView _dv =
new
DataView();
protected
void
Page_PreInit(
object
sender, EventArgs e)
{
// controllo autenticazione
// se il ruolo non è quello giusto esco dalla sessione
if
(Session[
"AuthIDRuolo"
] !=
null
&& (
int
)Session[
"AuthIDRuolo"
] >= 3)
{ }
/* in fase di test va commentata
else
Response.Redirect("~/Account/Login?LOGOUT=1");
*/
// carica la stringa di connessione
if
(ConfigurationManager.AppSettings[
"ModoTest"
] ==
"true"
)
_connDb = ConfigurationManager.ConnectionStrings[
"MAVTest"
].ConnectionString;
else
_connDb = ConfigurationManager.ConnectionStrings[
"MAV"
].ConnectionString;
/* test, per non dover sempre fare il login */
Session[
"AuthIDRuolo"
] = 4;
Session[
"AuthMatricola"
] = 3877;
Session[
"AuthNome"
] =
"Emanuele"
;
Session[
"AuthNomeCompleto"
] =
" LANZA Emanuele"
;
Session[
"AuthIDUtente"
] = 1;
Session[
"Browser"
] =
"IE11"
;
try
{
}
catch
(Exception ex)
{
}
}
protected
void
Page_Init(
object
sender, EventArgs e)
{
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
dsMAV.SelectCommand =
"SELECT IDRegistrazione, Nome, Cognome, CF, EmailUPO, CodiceRuolo, Telefono, DataRichiesta, DataAbilitazione, IDOperatoreAbilitazione FROM Registrazioni ORDER BY DataAbilitazione, DataRichiesta"
;
// WHERE IDRegistrazione = 0
}
else
{
//int i = 0;
Cerca();
//btnExport.Visible = true;
}
}
protected
void
rgRichieste_PreRender(
object
sender, EventArgs e)
{
if
(
false
)
{
btnExport.Enabled =
false
;
btnExport.CssClass =
"disabled btn btn-default btn-sm"
;
}
else
{
btnExport.Enabled =
true
;
btnExport.CssClass =
"btn btn-default btn-sm"
;
}
}
protected
void
btnExport_Click(
object
sender, EventArgs e)
{
// limitare il numero di record esportabili, per evitare eccezioni out of memory (si può accettare fino a circa 8500 record non espansi)
// il formato csv non supporta la gerarchia, per altre modalità :
// esporta da radgrid: utilizzabile sino a 8500 record non espansi su csv -> 800MB in memoria di IIS
//rgPagamenti.MasterTableView.ExportToCSV();
string
modo =
"Excel"
;
// [Excel, CSV]
// qui invece esporta da datasource e non ha il problema perchè con 33000 record sto sotto i 210MB di IIS su CSV invece con excel arriva a 253MB
DataTable dt =
new
DataTable();
dt = _dv.ToTable();
if
(modo ==
"CSV"
)
{
string
csv = dt.ToCSV(
"\""
);
WriteToOutput(csv,
"export.csv"
,
"text/csv"
);
}
else
{
DumpExcel(dt);
}
}
protected
void
DumpExcel(DataTable tbl)
{
using
(ExcelPackage pck =
new
ExcelPackage())
{
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add(
"Rendiconti"
);
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells[
"A1"
].LoadFromDataTable(tbl,
true
);
//Format the header
using
(ExcelRange rng = ws.Cells[
"A1:M1"
])
{
rng.Style.Font.Bold =
true
;
//rng.Style.Fill.PatternType = ExcelFillStyle.Solid; //Set Pattern for the background to Solid
//rng.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189)); //Set color to dark blue
//rng.Style.Font.Color.SetColor(Color.White);
}
//Example how to Format Column 1 as numeric
using
(ExcelRange col = ws.Cells[2, 5, 2 + tbl.Rows.Count, 5])
{
// valuta
col.Style.Numberformat.Format = @
"#,##0.00\ [$€-1]"
;
}
using
(ExcelRange col = ws.Cells[2, 7, 2 + tbl.Rows.Count, 7])
{
// data
col.Style.Numberformat.Format = @
"dd/mm/yyyy"
;
}
using
(ExcelRange col = ws.Cells[2, 8, 2 + tbl.Rows.Count, 8])
{
// data
col.Style.Numberformat.Format = @
"dd/mm/yyyy"
;
}
//Write it back to the client
Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
;
Response.AddHeader(
"content-disposition"
,
"attachment; filename=Rendiconti.xlsx"
);
Response.BinaryWrite(pck.GetAsByteArray());
}
}
protected
void
btnCerca_Click(
object
sender, EventArgs e)
{
//Cerca();
// per ora chiamo la procedura nel Load e funziona poichè ho un solo pulsante di comando
}
protected
void
Cerca()
{
//string comando = "SELECT IDRendicontazione, [Matricola], [CodiceFiscale], [Nominativo], [Importo], [F_Scrigno], [DataIncasso], [DataContabile], Disposizione, Transazione, [Causale], [NProvvisorio], [MavKey] FROM [Rendicontazioni] ";
string
comando =
"SELECT IDRegistrazione, Nome, Cognome, CF, EmailUPO, CodiceRuolo, Telefono, DataRichiesta, DataAbilitazione, IDOperatoreAbilitazione FROM Registrazioni"
;
// WHERE IDRegistrazione = 0
//dsMAV.SelectCommand = " IDRendicontazione = 0";
//RadDatePickInizio.DateInput.SelectedDate;
comando +=
" ORDER BY DataAbilitazione, DataRichiesta"
;
dsMAV.SelectCommand = comando;
// +condizione;
//rgRichieste.DataBind();
rgRichieste.Rebind();
// http://www.telerik.com/help/aspnet-ajax/grid-most-common-mistakes.html
// conta i record
_dv = (DataView)dsMAV.Select(DataSourceSelectArguments.Empty);
//int nRisultati = dv.Table.Rows.Count;
_nRec = _dv.Table.Rows.Count;
}
protected
void
rgRichieste_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
rgRichieste.DataSource = dsMAV;
//int i = 0;
}
/*
protected void rgRichieste_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
{
rgRichieste.CurrentPageIndex = e.NewPageIndex;
rgRichieste.DataBind();
}
*/
private
void
WriteToOutput(String csv, String fileName, String mimeType)
{
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader(
"Content-Disposition"
, String.Format(
"attachment;filename={0}"
, fileName));
Response.Write(csv);
Response.End();
}
protected
void
rgRichieste_ItemCommand(
object
sender, GridCommandEventArgs e)
{
int
id = (
int
)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][
"IDRegistrazione"
];
// abilitazione utente
if
(e.CommandName ==
"Abilita"
)
{
ToggleRichiesta(1, id);
}
// disabilitazione utente
if
(e.CommandName ==
"Disabilita"
)
{
ToggleRichiesta(0, id);
}
Cerca();
}
protected
void
ToggleRichiesta(
int
modo,
int
idRichiesta)
{
SqlConnection connessione;
string
sqlCmd =
""
;
if
(modo == 1)
{
// abilita
try
{
connessione =
new
SqlConnection(_connDb);
connessione.Open();
SqlCommand comando =
new
SqlCommand(sqlCmd, connessione);
DateTime adesso = DateTime.Now;
sqlCmd =
" UPDATE Registrazioni SET DataAbilitazione = @dataAb, IDOperatoreAbilitazione = @idOp WHERE IDRegistrazione = @id"
;
comando.CommandText = sqlCmd;
comando.Parameters.Clear();
comando.Parameters.AddWithValue(
"@id"
, idRichiesta);
comando.Parameters.AddWithValue(
"@dataAb"
, adesso);
comando.Parameters.AddWithValue(
"@idOp"
, Session[
"AuthIDUtente"
]);
comando.ExecuteNonQuery();
connessione.Close();
// invia mail
/*
// invio mail di avviso a operatori e promemoria ad utente
string strEMail = "Gentile " + txtNome.Text + ", abbiamo ricevuto la sua richiesta di registrazione.\r\r";
strEMail += "I dati da lei comunicati sono:\rNome: " + txtNome.Text + "\rCognome: " + txtCognome.Text;
strEMail += "\rCF: " + txtCF.Text + "\rRuolo: " + ddlRuolo.SelectedValue;
if (txtTelefono.Text != "")
strEMail += "\rTel.: " + txtTelefono.Text;
strEMail += "\r\rLa procedura di abilitazione verrà completata entro 3 giorni lavorativi.";
strEMail += "\r\rUniversità del Piemonte Orientale - www.uniupo.it";
InvioMail posta = new InvioMail();
posta.AvvisoInoltroRegistrazione(txtEmailUPO.Text, strEMail);
// log ?
*/
//rgRichieste.Rebind();
}
catch
(Exception ex)
{
// messaggio di errore
lblErrore.Text = ex.Message;
ErrorMessage.Visible =
true
;
}
}
else
{
// disabilita
try
{
connessione =
new
SqlConnection(_connDb);
connessione.Open();
SqlCommand comando =
new
SqlCommand(sqlCmd, connessione);
DateTime adesso = DateTime.Now;
sqlCmd =
" UPDATE Registrazioni SET DataAbilitazione = NULL, IDOperatoreAbilitazione = @idOp WHERE IDRegistrazione = @id"
;
comando.CommandText = sqlCmd;
comando.Parameters.Clear();
comando.Parameters.AddWithValue(
"@id"
, idRichiesta);
comando.Parameters.AddWithValue(
"@dataAb"
, adesso);
comando.Parameters.AddWithValue(
"@idOp"
, Session[
"AuthIDUtente"
]);
comando.ExecuteNonQuery();
connessione.Close();
// invia mail
/*
// invio mail di avviso a operatori e promemoria ad utente
string strEMail = "Gentile " + txtNome.Text + ", abbiamo ricevuto la sua richiesta di registrazione.\r\r";
strEMail += "I dati da lei comunicati sono:\rNome: " + txtNome.Text + "\rCognome: " + txtCognome.Text;
strEMail += "\rCF: " + txtCF.Text + "\rRuolo: " + ddlRuolo.SelectedValue;
if (txtTelefono.Text != "")
strEMail += "\rTel.: " + txtTelefono.Text;
strEMail += "\r\rLa procedura di abilitazione verrà completata entro 3 giorni lavorativi.";
strEMail += "\r\rUniversità del Piemonte Orientale - www.uniupo.it";
InvioMail posta = new InvioMail();
posta.AvvisoInoltroRegistrazione(txtEmailUPO.Text, strEMail);
// log ?
*/
//rgRichieste.Rebind();
}
catch
(Exception ex)
{
// messaggio di errore
lblErrore.Text = ex.Message;
ErrorMessage.Visible =
true
;
}
}
}
protected
void
rgRichieste_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
int
i = 0;
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
string
strTxt = item[
"DataAbilitazione"
].Text.ToString();
LinkButton lnkAb = (LinkButton)e.Item.FindControl(
"btnAbilita"
);
LinkButton lnkDisab = (LinkButton)e.Item.FindControl(
"btnDisabilita"
);
if
(strTxt ==
" "
)
{
// non abilitato
lnkAb.Enabled =
true
;
lnkAb.CssClass =
"btn btn-default btn-sm"
;
lnkDisab.Enabled =
false
;
lnkDisab.CssClass =
"btn btn-default btn-sm disabled"
;
}
else
{
// abilitato
lnkAb.Enabled =
false
;
lnkAb.CssClass =
"btn btn-default btn-sm disabled"
;
lnkDisab.Enabled =
true
;
lnkDisab.CssClass =
"btn btn-default btn-sm"
;
}
//(item["Azione"].Controls[0] as LinkButton).Enabled = false;
//(item["Azione"].Controls[1] as LinkButton).Enabled = false; // btnAbilita
}
}
}
}
Thanks
0
Hello Emanuele,
I have examined your implementation and I have noticed that you are binding the grid through the DataSourceID property, with Simple Data-Binding and Advanced Data-Binding at the same time. Please note that this is not supported scenario and you will have to choose one of those approaches in order to allow the RadGrid to work properly.
If you are going to use complex operations like paging, filtering, editing, sorting, etc., you need to use the Advanced Data-Binding by handling the OnNeedDataSource event only.
Please modify your code accordingly and see if the issue will be resolved.
Regards,
Konstantin Dikov
Telerik
I have examined your implementation and I have noticed that you are binding the grid through the DataSourceID property, with Simple Data-Binding and Advanced Data-Binding at the same time. Please note that this is not supported scenario and you will have to choose one of those approaches in order to allow the RadGrid to work properly.
If you are going to use complex operations like paging, filtering, editing, sorting, etc., you need to use the Advanced Data-Binding by handling the OnNeedDataSource event only.
Please modify your code accordingly and see if the issue will be resolved.
Regards,
Konstantin Dikov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0

Emanuele
Top achievements
Rank 1
Veteran
answered on 03 Mar 2015, 10:15 AM
Hi Konstantin, i've modified code deleting DataSourceID assignment in RadGrid and MasterTableView.
Unfortunately the error has not disappeared.
If i launch the release version i can see in the js console (IE) this message on the order action:
SCRIPT5007: Unable to retrieve the 'PRM_ServerError' property of a null or undefined reference
File: RichiesteReg, riga: 1, colonna: 118032
Unfortunately the error has not disappeared.
If i launch the release version i can see in the js console (IE) this message on the order action:
SCRIPT5007: Unable to retrieve the 'PRM_ServerError' property of a null or undefined reference
File: RichiesteReg, riga: 1, colonna: 118032
0
Accepted
Hi Emanuele,
Could you please refer to the answer in the support ticket (Ticket ID: 912180) that you have opened regarding the same issue.
For both sides convenience I could suggest that we continue our conversation in the support ticket if any further assistance is needed.
Best Regards,
Konstantin Dikov
Telerik
Could you please refer to the answer in the support ticket (Ticket ID: 912180) that you have opened regarding the same issue.
For both sides convenience I could suggest that we continue our conversation in the support ticket if any further assistance is needed.
Best Regards,
Konstantin Dikov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.