Hi adnanali,
I have created sample that full-fill your requirement by refering the below links.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox runat="server" ID="txtCountry" AutoPostBack="true" OnTextChanged="TextChanged" />
<hr />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
</rsweb:ReportViewer>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Customers dsCustomers = GetData("SELECT TOP 10 CustomerID,ContactName,City,Country FROM Customers");
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
BindReport(dsCustomers);
}
}
private void BindReport(DataSet dsCustomers)
{
ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
protected void TextChanged(object sender, EventArgs e)
{
string country = txtCountry.Text.Trim();
BindReport(GetFilteredDataSet("Customers_GetCustomersCountryWise", country));
}
private DataSet GetFilteredDataSet(string procedure, string country)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
SqlCommand cmd = new SqlCommand();
if (!string.IsNullOrEmpty(country))
{
cmd.Parameters.Add(new SqlParameter("@CountryName", txtCountry.Text.Trim()));
}
cmd.Connection = con;
cmd.CommandText = procedure;
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds);
}
return ds;
}
}
private Customers 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 (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dsCustomers As Customers = GetData("SELECT TOP 10 CustomerID,ContactName,City,Country FROM Customers")
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
BindReport(dsCustomers)
End If
End Sub
Private Sub BindReport(dsCustomers As DataSet)
Dim datasource As New ReportDataSource("Customers", dsCustomers.Tables(0))
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)
End Sub
Protected Sub TextChanged(sender As Object, e As EventArgs)
Dim country As String = txtCountry.Text.Trim()
BindReport(GetFilteredDataSet("Customers_GetCustomersCountryWise", country))
End Sub
Private Function GetFilteredDataSet(procedure As String, country As String) As DataSet
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Dim cmd As New SqlCommand()
If Not String.IsNullOrEmpty(country) Then
cmd.Parameters.Add(New SqlParameter("@CountryName", txtCountry.Text.Trim()))
End If
cmd.Connection = con
cmd.CommandText = procedure
cmd.CommandType = CommandType.StoredProcedure
Dim ds As New DataSet()
Using da As New SqlDataAdapter(cmd)
da.Fill(ds)
End Using
Return ds
End Using
End Function
Private Function GetData(query As String) As Customers
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim cmd As New SqlCommand(query)
Using con As New SqlConnection(conString)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dsCustomers As New Customers()
sda.Fill(dsCustomers, "DataTable1")
Return dsCustomers
End Using
End Using
End Using
End Function
Procedure
--EXEC Customers_GetCustomersCountryWise 'France'
--EXEC Customers_GetCustomersCountryWise
CREATE PROCEDURE [dbo].[Customers_GetCustomersCountryWise]
@CountryName VARCHAR(15) = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 10 [CustomerID]
,[ContactName]
,[City]
,[Country]
FROM Customers
WHERE Country = @CountryName OR @CountryName IS NULL
END
Screenshot
![](https://i.imgur.com/vBVpuXL.gif)