动态报表构建Refresh()不会更改数据 [英] Dynamic Report building Refresh() is not changing data

查看:73
本文介绍了动态报表构建Refresh()不会更改数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从代码后面动态查看报告。但是当参数从页面中添加的动态文本框更改时。在报告refresh()中数据没有改变。



我在!IsPostback中调用sqlDS()和reportBuild()。





此方法用于定义sqlDatasource:



  protected   void  sqlDS()
{
string conString,prName = ;
int counter = 0 ;
报告代表= 报告();
rep = rep.searchReport(repID_HF.Value);

报告repFold = 报告();
repFold = repFold.searchFolder(foldID_HF.Value);

if (repFold.FolderName.Split(' (')[ 1 ] == Web Reports)
{
conString = dbSql.connectionStringAll;
prName = dbSql.providerName;
}
else
{
conString = db.connectionStringAll;
prName = db.providerName;
}
SqlDataSource1.ConnectionString = conString;
SqlDataSource1.ProviderName = prName;

string sqlString = System.IO.File.ReadAllText(Server.MapPath( 〜/ Reports / SQLs / + rep.SqlFile));
sqlString.Replace(System.Environment.NewLine, );


SqlDataSource1.SelectCommand = sqlString;

SqlDataSource1.CancelSelectOnNullParameter = false ;

报告repParam = new Reporting();

allPs = repParam.getAllParamRep(rep.RepID);


foreach (报告itemParam in allPs)
{
if (itemParam.ParamType == 日期
{
SqlDataSource1.SelectParameters.Add( + itemParam.ParamName,itemParam.ParamDefaultValue);
counter ++;
}
else if (itemParam.ParamType == Text
{
SqlDataSource1.SelectParameters.Add( + itemParam.ParamName,itemParam.ParamDefaultValue);
counter ++;
}
else if (itemParam.ParamType == 菜单
{
counter ++;
}
}
}





此方法用于声明报告属性:



 受保护  void  reportBuild()
{
报告rep2 = 报告();
rep2 = rep2.searchReport(repID_HF.Value);

ReportViewer1.LocalReport.ReportPath = Reports / RDLC / + rep2 .RdlcFile;
this .ReportViewer1.LocalReport.ReportEmbeddedResource = rep2.RdlcFile;

ReportParameter [] paramss = new ReportParameter [SqlDataSource1.SelectParameters.Count];

for int i = 0 ; i < SqlDataSource1.SelectParameters.Count; i ++)
{
paramss [i] = new ReportParameter(SqlDataSource1.SelectParameters [i] .Name.Split(' : ')[ 1 ],SqlDataSource1.SelectParameters [i] .DefaultValue);
}
ReportDataSource rds = new ReportDataSource(rep2.DatasetName.Split(' 。')[ 0 ],SqlDataSource1);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);

// paramss [0] = new ReportParameter(TDATE,SqlDataSource1.SelectParameters [ 0] .DefaultValue);
// paramss [1] = new ReportParameter(CUST_NUM ,SqlDataSource1.SelectParameters [1] .DefaultValue);
ReportViewer1.LocalReport.SetParameters(paramss);

ReportViewer1.LocalReport.Refresh();

}
在reportViewer刷新方法中,我尝试 set new 参数根据动态文本框添加 页面:

protected void ReportViewer1_ReportRefresh( object sender,System.ComponentModel.CancelEventArgs e)
{
foreach (Control txt > Panel1.Controls)
{
if (txt TextBox)
{
txts.Add(txt);
}
}

foreach (TextBox txtbox in txts)
{

报告repP = 报告();
repP = repP.searchParam(txtbox.Attributes [ pID]。ToString() );
if (repP.ParamType == 日期
{
SqlDataSource1.SelectParameters [ + repP.ParamName] .DefaultValue = txtbox.Text;
}
else if (repP.ParamType == Text
{
SqlDataSource1.SelectParameters [ + repP.ParamName] .DefaultValue = txtbox.Text;
}
}

// 报告r =新报告( );
// r = r.searchReport(repID_HF.Value);


// 报告代表=新报告();
// rep = rep.searchReport(repID_HF.Value);

// ReportDataSource rds = new ReportDataSource(rep.DatasetName.Split('。')[0], SqlDataSource1);
// this.ReportViewer1.Reset();
// ReportViewer1.LocalReport.DataSources.Clear();
< span class =code-comment> // ReportViewer1.LocalReport.DataSources.Add(rds);

ReportParameterInfoCollection x = ReportViewer1.LocalReport.GetParameters();
// Response.Redirect(Request.RawUrl);
ReportViewer1.LocalReport .REFRESH();

}





我试过调试,发现每个东西都正常工作,SQL参数改变了,报告参数也改变了。



为什么报告中的数据不会改变? Plz帮帮我

解决方案

试试这个





reportViewer1.LocalReport。 DataSources.Clear();

reportViewer1.LocalReport.DataSources.Add(datasource);

this.reportViewer1.RefreshReport();


< blockquote>

谢谢我有一个更好更简单的方法来解决这个问题使用这个链接

http://www.igregor.net/post/2007/12/Adding -Controls-to-an-ASPNET-form-Dynamically.aspx

你可以使用字符串数组来传递属性。


I am trying to View a report dynamically from code behind. But when the parameters are changed from dynamic textboxes added in the page. in the report refresh() the data is not changed.

I call sqlDS() and reportBuild() in the !IsPostback.


This method is for defining the sqlDatasource:

protected void sqlDS()
{
    string conString, prName = "";
    int counter = 0;
    Reporting rep = new Reporting();
    rep = rep.searchReport(repID_HF.Value);

    Reporting repFold = new Reporting();
    repFold = repFold.searchFolder(foldID_HF.Value);

    if (repFold.FolderName.Split('(')[1] == "Web Reports)")
    {
        conString = dbSql.connectionStringAll;
        prName = dbSql.providerName;
    }
    else
    {
        conString = db.connectionStringAll;
        prName = db.providerName;
    }
    SqlDataSource1.ConnectionString = conString;
    SqlDataSource1.ProviderName = prName;

    string sqlString = System.IO.File.ReadAllText(Server.MapPath("~/Reports/SQLs/" + rep.SqlFile));
    sqlString.Replace(System.Environment.NewLine, " ");


    SqlDataSource1.SelectCommand = sqlString;

    SqlDataSource1.CancelSelectOnNullParameter = false;

    Reporting repParam = new Reporting();

    allPs = repParam.getAllParamRep(rep.RepID);


    foreach (Reporting itemParam in allPs)
    {
        if (itemParam.ParamType == "Date")
        {
            SqlDataSource1.SelectParameters.Add(":" + itemParam.ParamName, itemParam.ParamDefaultValue);
            counter++;
        }
        else if (itemParam.ParamType == "Text")
        {
            SqlDataSource1.SelectParameters.Add(":" + itemParam.ParamName, itemParam.ParamDefaultValue);
            counter++;
        }
        else if (itemParam.ParamType == "Menu")
        {
            counter++;
        }
    }
}



This method is for declaring the report properties:

        protected void reportBuild()
        {
            Reporting rep2 = new Reporting();
            rep2 = rep2.searchReport(repID_HF.Value);

            ReportViewer1.LocalReport.ReportPath = "Reports/RDLC/" + rep2.RdlcFile;
            this.ReportViewer1.LocalReport.ReportEmbeddedResource = rep2.RdlcFile;

            ReportParameter[] paramss = new ReportParameter[SqlDataSource1.SelectParameters.Count];

            for (int i = 0; i < SqlDataSource1.SelectParameters.Count; i++)
            {
                paramss[i] = new ReportParameter(SqlDataSource1.SelectParameters[i].Name.Split(':')[1], SqlDataSource1.SelectParameters[i].DefaultValue);
            }
                ReportDataSource rds = new ReportDataSource(rep2.DatasetName.Split('.')[0], SqlDataSource1);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(rds);

            //paramss[0] = new ReportParameter("TDATE", SqlDataSource1.SelectParameters[0].DefaultValue);
            //paramss[1] = new ReportParameter("CUST_NUM", SqlDataSource1.SelectParameters[1].DefaultValue);
            ReportViewer1.LocalReport.SetParameters(paramss);

            ReportViewer1.LocalReport.Refresh();

        }
In the reportViewer refresh method i try to set the new parameters according to the dynamic textboxes added in the page:

        protected void ReportViewer1_ReportRefresh(object sender, System.ComponentModel.CancelEventArgs e)
        {
            foreach (Control txt in Panel1.Controls)
            {
                if (txt is TextBox)
                {
                    txts.Add(txt);
                }
            }

            foreach (TextBox txtbox in txts)
            {

                Reporting repP = new Reporting();
                repP = repP.searchParam(txtbox.Attributes["pID"].ToString());
                if (repP.ParamType == "Date")
                {
                    SqlDataSource1.SelectParameters[":" + repP.ParamName].DefaultValue = txtbox.Text;
                }
                else if (repP.ParamType == "Text")
                {
                    SqlDataSource1.SelectParameters[":" + repP.ParamName].DefaultValue = txtbox.Text;
                }
            }

            //Reporting r = new Reporting();
            //r = r.searchReport(repID_HF.Value);


            //Reporting rep = new Reporting();
            //rep = rep.searchReport(repID_HF.Value);

            //ReportDataSource rds = new ReportDataSource(rep.DatasetName.Split('.')[0], SqlDataSource1);
            //this.ReportViewer1.Reset();
            //ReportViewer1.LocalReport.DataSources.Clear();
            //ReportViewer1.LocalReport.DataSources.Add(rds);

            ReportParameterInfoCollection x = ReportViewer1.LocalReport.GetParameters();
            //Response.Redirect(Request.RawUrl);
            ReportViewer1.LocalReport.Refresh();

        }



I tried debugging and found every thing is working correctly the SQL parameters changed, the Report Parameters also is changed.

so why the data in the report is not changed? Plz help me

解决方案

try this


reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(datasource);
this.reportViewer1.RefreshReport();


Thanks I got a better and easier way to solve this problem using this link

http://www.igregor.net/post/2007/12/Adding-Controls-to-an-ASPNET-form-Dynamically.aspx

And you can use array of strings to pass attributes.


这篇关于动态报表构建Refresh()不会更改数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆