Ciao a tutti,
in una pagina ho due gridview (due oggetti della libreria Obout, nella fattispecie) che popolo con un datareader nell'evento Page_PreRenderComplete. Durante il RowDataBound valorizzo il footer contenente le somme o le medie delle rispettive colonne.
Il problema è che la prima volta che premo il tasto per il popolamento delle gridview (il tasto in realtà serve solo per scatenare il postback), queste vengono visualizzate vuote, mentre tutte le altre volte funziona tutto correttamente.
//kpi è l'istanza di una classe che contiene tutti i valori di una
//singola row del datareader
private KPI kpi = new KPI();
//nell'evento prerendercomplete viene richiamata la seguente funzione:
void BindGridT1()
{
GridPopolate = false;
kpi = new KPI();
if (IsPostBack)
{
try
{
Contatore1 = 0;
Contatore2 = 0;
grid1.DataSource = dm.RecuperaDati(txtDate.Text, ComboAnno.Text, ComboMese.Text, ComboSett.Text);
NumeroGiorni = dm.NumeroGiorni;
grid1.DataBind();
Contatore1 = 0;
Contatore2 = 0;
grid2.DataSource = dm.RecuperaDati(txtDate.Text, ComboAnno.Text, ComboMese.Text, ComboSett.Text);
NumeroGiorni = dm.NumeroGiorni;
grid2.DataBind();
GridPopolate = true;
UpdatePanel1.Update();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
//Durante il RowDataBound, formatto le celle e calcolo i valori per
// il footer
public void RowDataBound(object sender, GridRowEventArgs e)
{
try
{
if (meseflag != "n" && NumeroGiorni != 0 && !GridPopolate)
{
System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
nfi.NumberGroupSeparator = ".";
if (((Grid)sender).ID == "grid1")
{
if (!IsPostBack)
{
}
if (e.Row.RowType == GridRowType.DataRow)
{
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(6, 2) + "/" + e.Row.Cells[0].Text.Substring(4, 2) + "/" + e.Row.Cells[0].Text.Substring(0, 4);
kpi.Data = e.Row.Cells[0].Text.Substring(6, 2) + "/" + e.Row.Cells[0].Text.Substring(4, 2) + "/" + e.Row.Cells[0].Text.Substring(0, 4);
kpi.ChiamateEntranti = (Convert.ToInt32(kpi.ChiamateEntranti) + Convert.ToInt32(e.Row.Cells[1].Text == "" ? "0" : e.Row.Cells[1].Text)).ToString();
kpi.ChiamateGestiteDaIVR = (Convert.ToInt32(kpi.ChiamateGestiteDaIVR) + Convert.ToInt32(e.Row.Cells[2].Text == "" ? "0" : e.Row.Cells[2].Text)).ToString();
kpi.ChiamateAbbandonateInCodaOperatore = (Convert.ToInt32(kpi.ChiamateAbbandonateInCodaOperatore) + Convert.ToInt32(e.Row.Cells[4].Text == "" ? "0" : e.Row.Cells[4].Text)).ToString();
kpi.ChiamateGestiteDaOperatore = (Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) + Convert.ToInt32(e.Row.Cells[6].Text == "" ? "0" : e.Row.Cells[6].Text)).ToString();
}
else if (e.Row.RowType == GridRowType.ColumnFooter)
{
e.Row.Cells[0].Text = "TOT.";
e.Row.Cells[1].Text = Convert.ToInt32(kpi.ChiamateEntranti).ToString("#,##0", nfi);
e.Row.Cells[2].Text = Convert.ToInt32(kpi.ChiamateGestiteDaIVR).ToString("#,##0", nfi);
e.Row.Cells[4].Text = Convert.ToInt32(kpi.ChiamateAbbandonateInCodaOperatore).ToString("#,##0", nfi);
e.Row.Cells[6].Text = Convert.ToInt32(kpi.ChiamateGestiteDaOperatore).ToString("#,##0", nfi);
e.Row.Cells[3].Text = ((Convert.ToInt32(kpi.ChiamateGestiteDaIVR) / (Double)Convert.ToInt32(kpi.ChiamateEntranti)) * 100).ToString("#0.00") + "%";
e.Row.Cells[5].Text = ((Convert.ToInt32(kpi.ChiamateAbbandonateInCodaOperatore) / (Double)(Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) + Convert.ToInt32(kpi.ChiamateAbbandonateInCodaOperatore))) * 100).ToString("#0.00") + "%";
e.Row.Cells[7].Text = ((Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) / (Double)(Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) + Convert.ToInt32(kpi.ChiamateAbbandonateInCodaOperatore))) * 100).ToString("#0.00") + "%";
e.Row.Cells<img src="/forum/skins/default/images/emo/png-blue/icon_smile_8ball.png" class="absmiddle emoticon" />.Text = ((Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) / (Double)Convert.ToInt32(kpi.ChiamateEntranti)) * 100).ToString("#0.00") + "%";
}
}
else
{
if (!IsPostBack)
{
}
if (e.Row.RowType == GridRowType.DataRow)
{
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(6, 2) + "/" + e.Row.Cells[0].Text.Substring(4, 2) + "/" + e.Row.Cells[0].Text.Substring(0, 4);
e.Row.Cells[1].Text = Math.Round(Convert.ToDouble(e.Row.Cells[1].Text), 2).ToString("#0.00");
e.Row.Cells[2].Text = Math.Round(Convert.ToDouble(e.Row.Cells[2].Text), 2).ToString("#0.00");
kpi.TempoMedioDiAttesa = (Convert.ToInt32(kpi.TempoMedioDiAttesa) + Convert.ToInt32(Math.Round(Convert.ToDouble(e.Row.Cells[1].Text == "" ? "0" : e.Row.Cells[1].Text), 2))).ToString();
kpi.DurataMediaDelleChiamate = (Convert.ToInt32(kpi.DurataMediaDelleChiamate) + Convert.ToInt32(Math.Round(Convert.ToDouble(e.Row.Cells[2].Text == "" ? "0" : e.Row.Cells[2].Text), 2))).ToString();
kpi.RisposteInSLA = (Convert.ToInt32(kpi.RisposteInSLA) + Convert.ToInt32(Convert.ToDouble(e.Row.Cells[3].Text == "" ? "0" : e.Row.Cells[3].Text))).ToString();
if (e.Row.Cells[1].Text != "" && e.Row.Cells[1].Text != "0") Contatore1++;
if (e.Row.Cells[2].Text != "" && e.Row.Cells[1].Text != "0") Contatore2++;
}
else if (e.Row.RowType == GridRowType.ColumnFooter)
{
e.Row.Cells[0].Text = "TOT.";
e.Row.Cells[1].Text = Math.Round((Convert.ToInt32(kpi.TempoMedioDiAttesa) / (Double)(Contatore1)), 2).ToString("#0.00");
e.Row.Cells[2].Text = Math.Round((Convert.ToInt32(kpi.DurataMediaDelleChiamate) / (Double)(Contatore2)), 2).ToString("#0.00");
e.Row.Cells[3].Text = Convert.ToInt32(kpi.RisposteInSLA).ToString("#,###", nfi);
if (Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) > 0)
{
e.Row.Cells[4].Text = (Convert.ToInt32(kpi.RisposteInSLA) / (Double)Convert.ToInt32(kpi.ChiamateGestiteDaOperatore) * 100).ToString("#0.00") + "%";
}
else
{
e.Row.Cells[4].Text = "0";
}
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Non riesco a capire il perchè di tale comportamento
Potete darmi una mano?
Grazie mille