0

我对使用ReportViewer. 我有一个问题,我不知道如何解决。

我有一个 DateTextBox和一个 Location TextBox。我的问题是,当用户键入日期和位置时,如何在ReportViewer. 下面是一些截图,以便更好地理解。任何帮助将不胜感激。

如果需要更多详细信息,请告诉我。

这是reportviewer 的report.rdlc。 下图中显示的 AllocationDate 和 LocationName 将在用户键入数据时显示日期和位置。

这是具有用于键入日期和位置的文本框的 Windows 窗体

4

1 回答 1

0

我假设您将ShowButton在表单中添加一个按钮。但是,您可以使用 TextBox 事件(例如 Focus Lost、Text Changed 等)而不是按钮单击事件。

   private void ShowButton_Click(object sender, EventArgs e)
    {
        DateTime allocationDate = Convert.ToDateTime(allocDateTextBox.Text);
        string   locationName   = locationTextBox.Text;

        //You can create as many datasources matching the name of DataSet in your report
        ReportDataSource rds = new ReportDataSource("DataSet1");
        rds.Value = getData(String.Format("Select * from myTable where theDate={0} AND Location={1}", allocationDate, locationName));

        reportViewer1.LocalReport.DataSources.Clear();

        //add as many datasources created above
        reportViewer1.LocalReport.DataSources.Add(rds);
        reportViewer1.RefreshReport();
    }

   private DataTable getData(string query)
   {
      //Select new record from database based on the new query with the new criteria
      //return the record as DataTable, DataSet or Collection of object
   }
于 2012-09-06T03:02:46.310 回答