Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello people,

I have a database in which i have a movies table it has two columns : Id and Movie.
I have used an autocomplete extender to extend the text box i have used LINQ to sql and written the web method.
Please look into it:
C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
    
      function pageLoad() {
      }
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 223px">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:Label ID="title" Text="Movie" AssociatedControlID="tb" runat="server" />
        <asp:TextBox ID="tb" runat="server" />
        <ajax:AutoCompleteExtender ID="ace1" TargetControlID="tb" 
             MinimumPrefixLength="1"  runat="server" 
            UseContextKey="True" ServiceMethod="GetCompletionList" />
          <asp:Button runat="server" OnClick="click" Text="submit" />
          <br /><br />
          
         <asp:Label ID="lbl" runat="server" />
    </div>
 
    </form>
</body>
</html>

code behind:
C#
protected void Page_Load(object sender, EventArgs e)
{


}
protected void click(object sender, EventArgs e)
{
    lbl.Text = tb.Text;
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefix, int count)
{
    DataClassesDataContext db = new DataClassesDataContext();
    return db.movies
        .Where(m => m.Movie.StartsWith(prefix)).OrderBy(m => m.Movie).Select(m => m.Movie).Take(count).ToArray();

}

Thanks and regards
Posted
Updated 25-Nov-13 17:12pm
v2

1 solution

I think this may help u

i am not sure

*may be you had to give web methord in List type

ASP.NET
 <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
                <asp:imagebutton id="Search" runat="server" imageurl="~/Images/search_button.png" xmlns:asp="#unknown">
                    OnClick="Select_TextBox1_AutoCompleteExtende" Style="margin: 2px -10px -11px;" />
                <ajaxitem:autocompleteextender id="AutoCompleteExtender1"  runat="server" enabled="True" xmlns:ajaxitem="#unknown">
                    ServiceMethod="GetListofCustomerName" MinimumPrefixLength="1" EnableCaching="true"
                    CompletionSetCount="2" CompletionInterval="1000" ServicePath="" TargetControlID="TextBox1">
                </ajaxitem:autocompleteextender>
</asp:imagebutton>


C#

C#
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetListofCustomerName(string prefixText)
{
    string cnnString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
    MySqlConnection con = new MySqlConnection(cnnString);

    MySqlCommand cmd2 = new MySqlCommand("select un from useraccount1 where un like '%" + prefixText + "%'", con);
    cmd2.Parameters.Add("prefixText", MySqlDbType.VarChar).Value = prefixText;
    MySqlDataAdapter da = new MySqlDataAdapter(cmd2);

    DataTable dt = new DataTable();
    da.Fill(dt);
    List<string> CountryNames = new List<string>();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        CountryNames.Add(dt.Rows[i]["name"].ToString());
    }
    return CountryNames;
}


Give me a Reply if this help's you..
 
Share this answer
 
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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