Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据集与RDLC报表的动态绑定_C#_Report_Rdlc_Dynamic Rdlc Generation - Fatal编程技术网

C# 数据集与RDLC报表的动态绑定

C# 数据集与RDLC报表的动态绑定,c#,report,rdlc,dynamic-rdlc-generation,C#,Report,Rdlc,Dynamic Rdlc Generation,我想将数据集动态绑定到rdlc。如果在ASPX文件(静态绑定)中使用内联数据源,则可以查看报告。但是,如果使用以下代码,报表查看器会一直显示“加载…”图像 我已经检查了数据集名称,如果我将数据集名称更改为“Orders2”,则表明未提供所需的数据集“Orders”。因此,我在表单上添加GridView并测试我的数据集。数据集包含数据,并与GridView配合良好 问题只在于报表,我无法将数据动态绑定到ReportViewer。请帮帮我。谢谢 protected void Page_Load(ob

我想将数据集动态绑定到rdlc。如果在ASPX文件(静态绑定)中使用内联数据源,则可以查看报告。但是,如果使用以下代码,报表查看器会一直显示“加载…”图像

我已经检查了数据集名称,如果我将数据集名称更改为“Orders2”,则表明未提供所需的数据集“Orders”。因此,我在表单上添加GridView并测试我的数据集。数据集包含数据,并与GridView配合良好

问题只在于报表,我无法将数据动态绑定到ReportViewer。请帮帮我。谢谢

protected void Page_Load(object sender, EventArgs e)
{
    DataSet ds = GetDataSet();
    ReportDataSource rds = new ReportDataSource("Orders", ds.Tables[0]);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.Refresh();

    GridView1.DataSource = ds;
    GridView1.DataBind();
}

private DataSet GetDataSet()
{
    var conString = ConfigurationManager.ConnectionStrings["dotnetConnectionString"];
    string strConnString = conString.ConnectionString;

    SqlConnection conn = new SqlConnection(strConnString);
    conn.Open();
    string sql = "Select * FROM Orders";

    SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();        
    ad.Fill(ds);

    return ds;
}
ASPX代码如下所示:

<form id="form1" runat="server">
<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="600px" Width="800px">
        <LocalReport ReportPath="Reports\Report.rdlc">
            <DataSources>
                <rsweb:ReportDataSource />
            </DataSources>
        </LocalReport>
    </rsweb:ReportViewer>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
</div>
</form>

在Pade_加载事件中,添加此代码

ReportViewer1.LocalReport.ReportPath = Server.MapPath("\\Reports\\Report.rdlc");
this.ReportViewer1.Width = 800;
this.ReportViewer1.Height = 600;

我已经解决了我的问题

问题是您需要在IsPostBack包装下添加代码

if (!Page.IsPostBack)
{
//your binding codes here
}

你能分享一下你对RDLC的设计吗。?如果我们是动态绑定数据集,那么rdlc设计如何?您是否仍然需要事先设计rdlc文件?或者您只是创建了rdlc文件,而没有插入任何表或绑定它?我对它进行了测试,如果我首先设计它——创建表并绑定数据集,它会完美地显示出来。但基于你的主要问题,我认为你是动态地做的。