Går det att skicka in en parameter till en rapport (rdlc) så att den sorterar på önskad kolumn? Hej, se om detta kan hjälpa dig Tack för infon!Sortera rapport med hjälp av parameter
Jag har provat med följande utan önskat resultat. Parametern jag skickar in i en tabell (tablix) ser ut så här "=Parameters!SortOnColumn.Value". Denna kopplar jag mot tablix->Sorting
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = "C:\Users\Mikael\Documents\Visual Studio 2013\Projects\Test av relationer\Test av relationer\Reports\Report2.rdlc"
'Skapa Rapportkällan
Dim rptDataSource As ReportDataSource
rptDataSource = New ReportDataSource("Kunder", dsKunder.Tables("Kunder"))
ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
'Skapa sorterings-parametern och skicka in kolumnnamnet jag vill sortera på.
Dim Sort As New ReportParameter("SortOnColumn", "Efternamn")
ReportViewer1.LocalReport.SetParameters(Sort)
ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
ReportViewer1.ZoomPercent = 100
ReportViewer1.ZoomMode = ZoomMode.Percent
ReportViewer1.RefreshReport()
Vad gör jag för fel? Om jag väljer sortering i designläge fungerar det som det ska. Det skiter sig (utan felmeddelanden) när jag sänder in parametern.
Sv: Sortera rapport med hjälp av parameter
http://cybarlab.com/pass-parameter-in-rdlc-report
Step 1
Select the form or page that will display the report. Add a ScriptManager on the top of the page.
Step 2
Design the UI according to parameters format. This example has only one parameter and its data type is integer. That’s why we are using one TextBox and Button.
Step 3
From the Toolbox add a ReportViewer control to the Web page or form.Set the Size and position of the control on the page or form.
Step4
Write the following C# code under the click event of Button1.
MyDataSetTableAdapters.TestProcedureTableAdapter ta = new MyDataSetTableAdapters.TestProcedureTableAdapter();
MyDataSet.TestProcedureDataTable dt = new MyDataSet.TestProcedureDataTable();
ta.Fill(dt, Convert.ToInt16(TextBox1.Text));
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1";
rds.Value = dt;
ReportParameter rp = new ReportParameter("Parameter1", TextBox1.Text.ToString());
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();
If the number of parameter is more then one, we need to change the code as like:
/ Suppose we have 2 parameters
MyDataSetTableAdapters.TestProcedureTableAdapter ta = new MyDataSetTableAdapters.TestProcedureTableAdapter();
MyDataSet.TestProcedureDataTable dt = new MyDataSet.TestProcedureDataTable();
ta.Fill(dt, Convert.ToInt16(TextBox1.Text), Convert.ToInt16(TextBox2.Text));
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1";
rds.Value = dt;
ReportParameter rp1 = new ReportParameter("Parameter1", TextBox1.Text.ToString());
ReportParameter rp2 = new ReportParameter("Parameter2", TextBox2.Text.ToString());
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp1, rp2 });
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();
We may include Microsoft.Reporting.WebForms namespace.
To preview the report build or deploy the application and browse that page or form.Sv:Sortera rapport med hjälp av parameter
Tror jag hittade felet. Parametern var fel. Så här ska den se ut. "=Fields(Parameters!SortOnColumn.Value).Value".