can you search Ajax Search in DropDownList?

0

Good I would like to help me I'm new to c # and I really do not know if it can be done in a DropDownList that combo is loaded with a database that fills but what I want is for you to select a value and automatically fill it my texbox as ajax is not used. I may close the question. If you could help me or an example please.

As a real Search Engine just show any value of the DropDownList

   protected void dprTarea_SelectedIndexChanged(object sender, EventArgs e)
        {


            string oficinas = "";
            oficinas = lblagencia.Text = Session["oficina"].ToString();

            SqlConnection conn = new SqlConnection();
            conn = new SqlConnection("server=172.16.1.124;    database=DBProAuxQP_QA;      user id=sa;                   password=SA123456789*;");
            conn.Open();

            string query = "select Fechacumplimiento from TTareasIngreso where descripcion='" + dprTarea.SelectedValue + "' ";
            SqlCommand cmd = new SqlCommand(query, conn);

            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.Read())
            {

                TxtFechaPago.Text = dr["Fechacumplimiento"].ToString();


            }
        }

    
asked by PieroDev 10.03.2017 в 21:05
source

2 answers

0

The correct syntax would be:


protected void dprTarea_SelectedIndexChanged(object sender, EventArgs e)
        {
            var val = dprTarea.SelectedItem.Value;
            using (SqlConnection con = new SqlConnection("server=172.16.1.124;    database=DBProAuxQP_QA;      user id=sa;                   password=SA123456789*;"))
            {
                using (SqlCommand cmd = new SqlCommand("SP_TTAREABUSCARFECHA", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@descripcionrubro", SqlDbType.VarChar).Value = val;
                    cmd.Parameters.Add("@agencia", SqlDbType.VarChar).Value = lblagencia.Text;
                    con.Open();
                    TxtFechaPago.Text = (String)cmd.ExecuteScalar();
                }

            }
}

Also to work and select a DropDownList the attribute AutoPostBack="true" must be activated since without this property the DropDownList will not work. For example, this should be:

  runat="server" Enabled="False" Height="16px" Width="162px" AutoPostBack="true" OnSelectedIndexChanged="dprTarea_SelectedIndexChanged">
    
answered by 11.03.2017 / 14:25
source
0

To change the value to a TextBox when you select a DropDownList item you have to use the SelectedIndexChanged event, then you put the code, I can not give you a more detailed example because you are not very specific with the question, if this does not help you clarify more what is your question

 protected void dprTarea_SelectedIndexChanged(object sender, EventArgs e)
    {    
        string oficinas = lblagencia.Text;

        SqlConnection conn = new SqlConnection();
        conn = new SqlConnection("server=172.16.1.124;    database=DBProAuxQP_QA;      user id=sa;                   password=SA123456789*;");
        conn.Open();

        string query = "select Fechacumplimiento from TTareasIngreso where descripcion='" + dprTarea.SelectedValue + "' ";
        SqlCommand cmd = new SqlCommand(query, conn);
        TxtFechaPago.Text = (string)cmd.ExecuteScalar();

        conn.Close();
    }
    
answered by 10.03.2017 в 21:17