使用linq到实体的autocompleteextender示例 [英] autocompleteextender example with linq to entities
本文介绍了使用linq到实体的autocompleteextender示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hai先生
当我想使用实体概念从数据库中检索数据时,
i在使用autocomplteextender控件时遇到问题。
请纠正我的问题
hai sir
i have a problem in using autocomplteextender control when i want to retrive data from database using entity concept.
please rectify my problem
推荐答案
你能否这个
http://stackoverflow.com/questions/2228229/autocomplete-extender-not-sorting -alphabetically
You Can You This
http://stackoverflow.com/questions/2228229/autocomplete-extender-not-sorting-alphabetically
你好,
试试这个 -
http: //www.eggheadcafe.com/tutorials/aspnet/77429274-e89f-49c2-a93a-b290f013f649/entity-framework-40-and-the-ajax-autocomplete-extender.aspx [ ^ ]
浏览我的代码如下;
在.aspx页面中添加此内容
< asp:textbox id =txtSearchUserNamerunat =serverwidth =400pxxmlns:asp =#unknown>
Go through my Code given bellow;
Add This in .aspx page
<asp:textbox id="txtSearchUserName" runat="server" width="400px" xmlns:asp="#unknown">
<asp:AutoCompleteExtender ServiceMethod="GetProductList"
MinimumPrefixLength="1"
CompletionInterval="0" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtSearchUserName"
ID="autoCompleteExtender1" runat="server" FirstRowSelected ="true">
</asp:AutoCompleteExtender>
< asp:button id =btnSearchUserNamerunat =serverxmlns:asp =#unknown>
OnClick =btnSearchUserName_ClickText =Search/> ;
放置代码在.cs页面如下所示,
<asp:button id="btnSearchUserName" runat="server" xmlns:asp="#unknown">
OnClick="btnSearchUserName_Click" Text="Search" />
Put the code in .cs Page as given bellow,
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] GetProductList(string prefixText, int count)
{
using (var context = new YourDataBaseConnection())
{
// Get the Products From Data Source. Change this method to use Database
var UserwebinarList = context.TableName.Where(c=>c.UserName!=null && c.IsActive==true) ;
List<String> userList = new List<String>();
foreach (var item in UserwebinarList)
{
userList.Add(item.UserName);
}
// Find All Matching Products
var list = from p in userList
where p.StartsWith(prefixText) || p.Contains(prefixText)
select p;
//Convert to Array as We need to return Array
string[] prefixTextArray = list.ToArray<String>();
//Return Selected Products
return prefixTextArray;
}
}
这篇关于使用linq到实体的autocompleteextender示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文