Hi fahimahmed,
I have created a sample please take its reference.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
Select Country :
<asp:DropDownList runat="server" ID="ddlCountries" DataSourceID="CountryDataSource"
AutoPostBack="true" DataTextField="Country" DataValueField="Country" AppendDataBoundItems="true"
OnSelectedIndexChanged="SelectedCountry">
<asp:ListItem Value="" Text="All Country"></asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="CountryDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:conString %>"
SelectCommand="SELECT DISTINCT [Country] FROM [Customers] WHERE Country IS NOT NULL">
</asp:SqlDataSource><br /><br />
<asp:GridView runat="server" ID="gvCustomers" AutoGenerateColumns="False" DataSourceID="CustomerDataSource">
<Columns>
<asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="CustomerDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:conString %>"
SelectCommand="SELECT [ContactName], [City], [Country] FROM [Customers]"></asp:SqlDataSource>
Code
C#
protected void SelectedCountry(object sender, EventArgs e)
{
string country = ddlCountries.SelectedValue;
CustomerDataSource.FilterExpression = " Country = '{0}' ";
CustomerDataSource.FilterParameters.Add(new ControlParameter("Country", "ddlCountries", "SelectedValue"));
}
VB.Net
Protected Sub SelectedCountry(ByVal sender As Object, ByVal e As EventArgs)
Dim country As String = ddlCountries.SelectedValue
CustomerDataSource.FilterExpression = " Country = '{0}' "
CustomerDataSource.FilterParameters.Add(New ControlParameter("Country", "ddlCountries", "SelectedValue"))
End Sub
Screenshot