Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create a web method and need to pass two values one from text box and anather is prefix value

C#
using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager
                    .ConnectionStrings["ConnectionString1"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                //string cmdText = "select ContactName from Customers where " +
                //"ContactName like @SearchText + '%'";

                string cmdText = "select MSupplier.pcode,MSupplier.pdesc from MM_Pomast inner join MSupplier on MSupplier.pcode=MM_Pomast.pcode " +
                " where MSupplier.loccode='" + loccode + "' And  MSupplier.divcode='" + divcode + "' And MSupplier.clicode='" + clicode + "'" +
                " and pdesc like '%'+@prefixText+'%'";

                cmd.Parameters.AddWithValue("@prefixText", prefixText);
                if (contextKey != null)
                {
                    cmdText += " and  MM_Pomast.pordcode = @contextKey";
                    cmd.Parameters.AddWithValue("@contextKey", contextKey);
                }
                cmd.CommandText = cmdText;
                cmd.Connection = conn;
                conn.Open();
                List<string> customers = new List<string>();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        customers.Add(sdr["pdesc"].ToString());
                    }
                }
                conn.Close();
                return customers;
            }

where i use this
in this prefix value is showing but value of @contextKey is not getting
then i use bellow java script in cs
JavaScript
function SetContextKey() {
        $find('AutoCompleteExtender1').set_contextKey($get("<%=Drppordcode.ClientID %>").value);
    }


set onkeyup for that perticular text box like bellow
onkeyup="SetContextKey()"

but still it not me given an value at context key

need a help very..
Posted

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