dropdownlist only refreshes the first time even with the selectedindexchange and postback true

0

I have a dropdownlist that has an event ddltiempo_SelectedIndexChanged which has to update a gridview every time it changes it makes a query to the bd, but only does it the first time (the dropdownlist already has autopostback true)

This is the code

protected void ddltiempo_SelectedIndexChanged(object sender, EventArgs e)
    {


            if (valortiempo!= 0)
            {
                tiempo= dc.Ex_Consultamonto(valortiempo);
            }
       gvcalendario.DataSource = tiempo.List();
       gvcalendario.DataBind();
}
    
asked by lucho 03.04.2018 в 18:09
source

1 answer

1

I understand that the flow is the following:

You change the value of the dropdown > does postback > does not load the gridview.

When you do the postback you may not have a treat to do something on the Page_Load.

        protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Si no es postback, primer inicio de la pagina
        }
        else
        {
            // Cuando es postback recoges el valor

            if (valortiempo != 0)
            {
                tiempo = dc.Ex_Consultamonto(valortiempo);
            }
            gvcalendario.DataSource = tiempo.List();
            gvcalendario.DataBind();
        }

    }
    
answered by 04.04.2018 в 10:31