1
Next, I have a gridview
that it needs to be inside a postback to be able to perform an update when selecting a checkbox. The problem is that I have a filter using a DropDownList
, if I leave mine PopularGVDuplicatas()
inside the same postback where the items are loaded, the filter does not work and the paging also. If I leave the PopularGVDuplicatas()
off the postback checkbox when checked does not work as it should. Someone can help?
Follows 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();
}
Solved.
I put the Populargvduplicatas() into ddlFiltro_TextChanged event and it worked.