Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a list of areas in dropdownlist,when user select area from dropdown am showing the list of employees of that particular area.Here i want to show A B C D E F.......Z
if user click A ,it will show employees name starting with A
Posted

Yes, you can do that with a little trick.

1. Show the distinct first later of employees from DB
Query like following can help to do so
SQL
SELECT DISTINCT LEFT(EmployeeName,1) FROM dbo.Employee

2. Show this with the help of a repeater control like
ASP.NET
<asp:repeater runat="server" id="repDemo" xmlns:asp="#unknown">
            <itemtemplate>
                <asp:linkbutton id="lnkDemo" text="<%#Eval("EmployeeName") %>" runat="server" onclick="lnkDemo_Click" />
            </itemtemplate>
        </asp:repeater>

3. Code behind should look like
C#
protected void lnkDemo_Click(object sender, EventArgs e)
    {
        //get the letter for which you will show the employee name
        string serachLetter = ((LinkButton)sender).Text.Trim();
        //logic to query and show the employee names starting with the 'searchLetter'
    }

2. While selecting an item from dropdownlist first show employees with name starts with 'A'
3. Then if user clicks on any other letter he/she can view the desired result

Hopefully this will help.
In case any further assistance is required please let me know :)
 
Share this answer
 

You can use Linq to get a sorted list based on a target string.


C#
 string[] names = { "Tom", "Dick", "Dan", "Tony", "Tim" };
 string key = "D";
 List<string> ListSortedByKey = names
 .Where(n => n.StartsWith(key))
 .OrderBy(n => n).ToList();
</string>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900