如何在asp.net中设置字母搜索(排序顺序) [英] How to set alphabetical search in asp.net(sorting order)
问题描述
我在下拉列表中有一个区域列表,当用户从下拉列表中选择区域时,显示该特定区域的员工列表。这里我想显示ABCDE F ....... Z
如果用户单击A,它将显示以A
开头的员工姓名。是的,你可以用一点技巧来做到这一点。
1.稍后向DB员工展示不同的员工
如下查询可以帮助这样做
SELECT DISTINCT LEFT (EmployeeName, 1 ) FROM dbo.Employee
2 。在转发器控件的帮助下显示此信息,例如
< 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.背后的代码看起来应该是
受保护 void lnkDemo _Click( object sender,EventArgs e)
{
// 获取您将显示员工姓名的字母
string serachLetter =((LinkButton)sender)。 Text.Trim();
// 用于查询和显示以'searchLetter'开头的员工姓名的逻辑
}
2.从下拉列表中选择项目时,首先显示名称以'A'开头的员工
3.然后,如果用户点击在任何其他信件上,他/她可以查看所需的结果
希望这会有所帮助。
如果需要任何进一步的帮助,请让我知道:)
您可以使用Linq根据目标字符串获取排序列表。
string [] names = { Tom , Dick, Dan, Tony , Tim};
string key = D跨度>;
List< string> ListSortedByKey = name
.Where(n = > n.StartsWith(key))
.OrderBy(n = > n).ToList();
< / string > 跨度>
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
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
SELECT DISTINCT LEFT(EmployeeName,1) FROM dbo.Employee
2. Show this with the help of a repeater control like
<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
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 :)
You can use Linq to get a sorted list based on a target string.
string[] names = { "Tom", "Dick", "Dan", "Tony", "Tim" }; string key = "D"; List<string> ListSortedByKey = names .Where(n => n.StartsWith(key)) .OrderBy(n => n).ToList(); </string>
这篇关于如何在asp.net中设置字母搜索(排序顺序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!