Hi Shivashank,
Please refer below sample.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="ddlCompanyName" runat="server" Height="25px" Width="120px"
DataSourceID="SqlDataSource1" DataTextField="ShipCountry" DataValueField="OrderID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ShipCountry], [OrderID] FROM [Orders]"></asp:SqlDataSource>
From
<asp:TextBox ID="txtFromD" runat="server" Height="22px" Width="120px"></asp:TextBox>
<asp:ImageButton ID="ImgCal1" runat="server" Height="25px" ImageAlign="Top" ImageUrl="~/calendar.png"
Width="30px" />
<cc1:CalendarExtender ID="txtFromD_CalendarExtender" runat="server" Enabled="True"
PopupButtonID="ImgCal1" PopupPosition="TopLeft" TargetControlID="txtFromD">
</cc1:CalendarExtender>
To :
<asp:TextBox ID="txtToD" runat="server" Height="22px" Width="120px"></asp:TextBox>
<cc1:CalendarExtender ID="txtToD_CalendarExtender" runat="server" Enabled="True"
PopupButtonID="ImgCal" PopupPosition="TopLeft" TargetControlID="txtToD">
</cc1:CalendarExtender>
<asp:ImageButton ID="ImgCal" runat="server" Height="25px" ImageAlign="Top" ImageUrl="~/calendar.png"
Width="30px" />
<asp:Button ID="btnClick" runat="server" Height="30px" Text="Search" Width="100px"
OnClick="btnClick_Click" ToolTip="Click Here" CssClass="btn" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
</rsweb:ReportViewer>
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report2.rdlc");
DataSet1 dsCustomers = GetData("select TOP 20 * from Orders");
ReportDataSource datasource = new ReportDataSource("DataSet1", dsCustomers.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
private DataSet1 GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet1 ds = new DataSet1())
{
sda.Fill(ds, "DataTable1");
return ds;
}
}
}
}
protected void btnClick_Click(object sender, EventArgs e)
{
string selectName = ddlCompanyName.SelectedItem.Text;
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
SqlCommand cmd = new SqlCommand("select * from Orders Where ShipCountry=@ShipCountry AND OrderDate Between @FromOrderDate AND @ToOrderDate", con);
cmd.Parameters.AddWithValue("@ShipCountry", selectName);
cmd.Parameters.AddWithValue("@FromOrderDate", txtFromD.Text);
cmd.Parameters.AddWithValue("@ToOrderDate", txtToD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
using (DataSet1 dsCustomers = new DataSet1())
{
da.Fill(dsCustomers, "DataTable1");
ReportDataSource datasource = new ReportDataSource("DataSet1", dsCustomers.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
}
Screenshot
