Problem with paging on account of loading GridView and DropDownList in same Page.PostBack

1

Next, I have a gridview that it needs to be inside a postback in order to run an update when selecting a checkbox. The problem is that I have a filter using a DropDownList , if I leave my PopularGVDuplicatas() within the same postback where the items are loaded, the filter does not work and the paging as well. If I leave PopularGVDuplicatas() out of postback the checkbox when checked does not work as it should. Can anyone help?

Follow the code.

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        ddlFiltro.Items.Insert(0, new ListItem("Somente abertas"));
        ddlFiltro.Items.Insert(1, new ListItem("Já pagas"));
        ddlFiltro.Items.Insert(2, new ListItem("Ambas"));

        PopularGVDuplicatas();
    }
}

public void PopularGVDuplicatas()
{
    MySqlConnection conn = new MySqlConnection(strCon);

    if (ddlFiltro.Text.Equals("Somente abertas"))
    {
        SQL = "consulta";
    }
    else if (ddlFiltro.Text.Equals("Já pagas"))
    {
        SQL = "consulta";
    }
    else if (ddlFiltro.Text.Equals("Ambas"))
    {
        SQL = "consulta";
    }
    else
    {
        SQL = "consulta";
    }

    MySqlDataAdapter adapter = new MySqlDataAdapter(SQL, conn);
    DataTable dt = new DataTable();

    conn.Open();
    if (conn.State == System.Data.ConnectionState.Open)
    {
        adapter.Fill(dt);
    }

    gvDuplicatas.AllowPaging = true;
    gvDuplicatas.PageSize = 100;
    gvDuplicatas.PagerSettings.Position = PagerPosition.TopAndBottom;
    gvDuplicatas.PagerSettings.Mode = PagerButtons.NumericFirstLast;
    gvDuplicatas.PagerSettings.PageButtonCount = 50;

    gvDuplicatas.PagerStyle.CssClass = "pagination-ys";
    gvDuplicatas.PagerStyle.HorizontalAlign = HorizontalAlign.Center;

    gvDuplicatas.DataSource = dt;
    gvDuplicatas.DataBind();

}

protected void gvDuplicatas_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    gvDuplicatas.PageIndex = e.NewPageIndex;
    gvDuplicatas.SelectedIndex = -1;

    PopularGVDuplicatas();
}

Fixed.

I placed the PopularGVDuplicatas () inside the ddlFiltro_TextChanged event and it worked.

    
asked by anonymous 13.03.2016 / 20:50

0 answers