Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<asp:TextBox ID="txt_vech_no" runat="server"></asp:TextBox>

                                                        <cc1:AutoCompleteExtender ID="AutoCompleteExtender4" runat="server" TargetControlID="txt_vech_no" MinimumPrefixLength="1"
                                                             EnableCaching="true" CompletionSetCount="1" CompletionInterval="0" ServiceMethod="get_vehicleno"></cc1:AutoCompleteExtender>




XML
[System.Web.Script.Services.ScriptMethod()]
       [System.Web.Services.WebMethod]
       public static List<string> get_vehicleno(string prefixText)
       {
           SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BMS"].ToString());
           con.Open();
           SqlCommand cmd15 = new SqlCommand("select * from tbl_vehicle where vehicle_registration_no like @Name+'%'", con);
           cmd15.Parameters.AddWithValue("@Name", prefixText);
           SqlDataAdapter da15 = new SqlDataAdapter(cmd15);
           DataTable dt15 = new DataTable();
           da15.Fill(dt15);
           List<string> CountryNames12 = new List<string>();
           for (int i = 0; i < dt15.Rows.Count; i++)
           {
               CountryNames12.Add(dt15.Rows[i][1].ToString());
           }
           return CountryNames12;
       }




Hi im using the above code for autoextender through out my project but its not working for this perticular textbox.please help me out.
Posted
Comments
[no name] 17-Oct-13 2:04am    
Not working means what..??what is the problem you are facing..
SarthakGowda 17-Oct-13 3:20am    
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> get_vehicleno(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BMS"].ToString());
con.Open();
SqlCommand cmd15 = new SqlCommand("select * from tbl_vehicle where vehicle_registration_no like @Name+'%'", con);
cmd15.Parameters.AddWithValue("@Name", txt_vech_no.Text.Trim());
SqlDataAdapter da15 = new SqlDataAdapter(cmd15);
DataTable dt15 = new DataTable();
da15.Fill(dt15);
List<string> CountryNames12 = new List<string>();
for (int i = 0; i < dt15.Rows.Count; i++)
{
CountryNames12.Add(dt15.Rows[i][1].ToString());
}
return CountryNames12;
}


It is throwing an error as "AN OBJECT REFERENCE IS REQUIRED FOR THE NON STATIC FIELD" near the code u sujjested.. cmd15.Parameters.AddWithValue("@Name", txt_vech_no.Text.Trim() );

1 solution

hi
your TargetControlID is txt_vech_no but you passed the value from prefixText Textbox.So for my suggestion you just pass txt_vech_no in place of prefixText and write the line of coding as

cmd15.Parameters.AddWithValue("@Name", txt_vech_no.Text.Trim() );
 
Share this answer
 
Comments
SarthakGowda 17-Oct-13 3:20am    
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> get_vehicleno(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BMS"].ToString());
con.Open();
SqlCommand cmd15 = new SqlCommand("select * from tbl_vehicle where vehicle_registration_no like @Name+'%'", con);
cmd15.Parameters.AddWithValue("@Name", txt_vech_no.Text.Trim());
SqlDataAdapter da15 = new SqlDataAdapter(cmd15);
DataTable dt15 = new DataTable();
da15.Fill(dt15);
List<string> CountryNames12 = new List<string>();
for (int i = 0; i < dt15.Rows.Count; i++)
{
CountryNames12.Add(dt15.Rows[i][1].ToString());
}
return CountryNames12;
}
Kamalkant(kk) 17-Oct-13 8:13am    
yes

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