我很擅长使用ReportViewer
。我有一个问题,我不知道如何解决。
我有一个日期TextBox
和一个位置TextBox
。我的问题是,当用户键入日期和位置时,如何在ReportViewer
中显示相同的数据。以下是一些更好理解的截图。任何帮助将不胜感激。
如果需要更多详细信息,请与我们联系。
答案 0 :(得分: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
}