如何解决reportviewer中的死循环?窗体
How to solve the infinite loop in reportviewer? winforms
我在 visual studio 2010 年使用 reportviewer,但是当我第一次打开报告时数据加载正确,但是当我切换到另一个报告并尝试 return第一个,reportviewer 保持加载状态。
我尝试使用 IsPostBack,但出现错误。
error
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CheckManagement
{
public partial class BeneficiariesDebtsViewer : Form
{
public BeneficiariesDebtsViewer()
{
InitializeComponent();
}
private void BeneficiariesDebtsViewer_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
// Report data source code...
reportViewer1.RefreshReport();
}
beneficiariesDebts.Clear();
LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();
BeneficiariesDebts debts = loader.LoadData();
foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
{
beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
}
reportViewer1.RefreshReport();
}
catch (System.Exception ex)
{
MessageBox.Show("Hubo un problema al realizar la operación:\n" + ex.Message,
"", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
非常感谢您的关注和帮助。
IsPostBack 不存在于 winform 项目中,仅存在于 Asp.net.
尝试使用 IsPostBack 删除 if 并重新运行项目。
吕克
我是通过以下方式解决的:
try
{
beneficiariesDebts.Clear();
LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();
BeneficiariesDebts debts = loader.LoadData();
foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
{
beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
}
this.reportViewer1.RefreshReport();
MessageBox.Show("La carga puede tardar unos minutos","Nota");
}
我添加了一个 MessageBox.Show 允许重新加载页面,这样我设法防止报告挂起。
我在 visual studio 2010 年使用 reportviewer,但是当我第一次打开报告时数据加载正确,但是当我切换到另一个报告并尝试 return第一个,reportviewer 保持加载状态。
我尝试使用 IsPostBack,但出现错误。
error
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CheckManagement
{
public partial class BeneficiariesDebtsViewer : Form
{
public BeneficiariesDebtsViewer()
{
InitializeComponent();
}
private void BeneficiariesDebtsViewer_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
// Report data source code...
reportViewer1.RefreshReport();
}
beneficiariesDebts.Clear();
LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();
BeneficiariesDebts debts = loader.LoadData();
foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
{
beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
}
reportViewer1.RefreshReport();
}
catch (System.Exception ex)
{
MessageBox.Show("Hubo un problema al realizar la operación:\n" + ex.Message,
"", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
非常感谢您的关注和帮助。
IsPostBack 不存在于 winform 项目中,仅存在于 Asp.net.
尝试使用 IsPostBack 删除 if 并重新运行项目。
吕克
我是通过以下方式解决的:
try
{
beneficiariesDebts.Clear();
LoadBeneficiaryDebts loader = new LoadBeneficiaryDebts();
BeneficiariesDebts debts = loader.LoadData();
foreach (BeneficiariesDebts.BeneficieriesDebtsTableRow row in debts.BeneficieriesDebtsTable)
{
beneficiariesDebts.BeneficieriesDebtsTable.AddBeneficieriesDebtsTableRow(row.BeneficiaryID, row.BeneficiaryName, row.TotalDebt, row.BeneficiariesTypes);
}
this.reportViewer1.RefreshReport();
MessageBox.Show("La carga puede tardar unos minutos","Nota");
}
我添加了一个 MessageBox.Show 允许重新加载页面,这样我设法防止报告挂起。