Hello phonghue,
Please refer the below codes.
Database
1For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:Panel ID="AdminPanel" runat="server" Visible="True">
<p>Search by Title:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="">--Select All--</asp:ListItem>
<asp:ListItem Value="Sales Representative">Sales Representative</asp:ListItem>
<asp:ListItem Value="Vice President, Sales">Vice President</asp:ListItem>
<asp:ListItem Value="Sales Manager">Sales Manager</asp:ListItem>
<asp:ListItem Value="Inside Sales Coordinator">Inside Sales Coordinator</asp:ListItem>
</asp:DropDownList>
</p>
</asp:Panel>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="EmployeeId" DataSourceID="SqlDataSource1">
<EmptyDataTemplate>
<span>No mentor is available at this time.</span>
</EmptyDataTemplate>
<ItemTemplate>
<div class="row border">
<div class="col-md-4">
<p>
<span class="lead font-weight-bold">Name:
<asp:Label ID="Fullname" runat="server" Text='<%# Eval("FirstName")%>' /></span>
<br />
<u>Title:</u>
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
<br />
<u>Country</u>
<asp:Label ID="CountryonLabel" runat="server" Text='<%# Eval("Country") %>' />
</p>
</div>
<%--<div class="col-md-8">
<strong>Profile Statement:</strong>
<br />
<asp:Label ID="MentorInterestLabel" runat="server" Text='<%# Eval("MentorInterest") %>' />
<br />
<br />
<strong>Weekly available schedule:</strong>
<br />
<br />
<strong>Monday: </strong>
<asp:Label ID="MonScheduleLabel" runat="server" Text='<%# Eval("MonSchedule") %>' />
<br />
<strong>Tuesday: </strong>
<asp:Label ID="TueScheduleLabel" runat="server" Text='<%# Eval("TueSchedule") %>' />
<br />
<strong>Wednesday:</strong>
<asp:Label ID="WedScheduleLabel" runat="server" Text='<%# Eval("WedSchedule") %>' />
<br />
<strong>Thursday:</strong>
<asp:Label ID="ThurScheduleLabel" runat="server" Text='<%# Eval("ThurSchedule") %>' />
<br />
<strong>Friday:</strong>
<asp:Label ID="FriScheduleLabel" runat="server" Text='<%# Eval("FriSchedule") %>' />
<br />
<strong>Saturday:</strong>
<asp:Label ID="SatScheduleLabel" runat="server" Text='<%# Eval("SatSchedule") %>' />
<br />
<strong>Sunday:</strong>
<asp:Label ID="SunScheduleLabel" runat="server" Text='<%# Eval("SunSchedule") %>' />
<br />
<br />
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<br />
<br />
</div>--%>
</div>
<p class="clearfloat"> </p>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" style="border: 1px solid #CCC; padding: 3px;" />
</div>
<div style="">
</div>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT FirstName As Fullname, * FROM [EMPLOYEES] WHERE ([Country] = @Country) AND ([Title] = @Title) ORDER BY [EmployeeId]">
<SelectParameters>
<asp:Parameter DefaultValue="USA" Name="Country" Type="String" />
<asp:Parameter DefaultValue="Sales Representative" Name="Title" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Code
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(DropDownList1.SelectedValue))
{
// All
SqlDataSource1.SelectCommand = "SELECT FirstName As Fullname, * FROM Employees ORDER BY EmployeeId";
}
else
{
SqlDataSource1.SelectCommand = "SELECT FirstName As Fullname, * FROM Employees WHERE ([Country] ='USA') AND (Title = '" + DropDownList1.SelectedValue + "') ORDER BY EmployeeId";
}
ListView1.DataBind();
}
VB.Net
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If String.IsNullOrEmpty(DropDownList1.SelectedValue) Then
SqlDataSource1.SelectCommand = "SELECT FirstName As Fullname, * FROM Employees ORDER BY EmployeeId"
Else
SqlDataSource1.SelectCommand = "SELECT FirstName As Fullname, * FROM Employees WHERE ([Country] ='USA') AND (Title = '" & DropDownList1.SelectedValue & "') ORDER BY EmployeeId"
End If
ListView1.DataBind()
End Sub
Screenshot