Defaultview.Rowfilter filter by date filter

Asked

Viewed 260 times

1

Good afternoon, I am filled a Gridview, but when I am going to perform the filter, it informs me the following error "Object reference not set for an instance of an object." The field I’m trying to filter, expire, is date type, and I use SQL. I have tried several ways, with # between dates, configuring, but without the same error occurs.

I tried so:

 ds.Tables["cantas_apagar"].DefaultView.RowFilter = String.Format(CultureInfo.InvariantCulture.DateTimeFormat, "vencimento >= # {0} #", txtDataInicial.Text) + "and" + String.Format(CultureInfo.InvariantCulture.DateTimeFormat, "vencimento <= # {0} #", txtDataInicial.Text);
                    GridView1.DataBind();

Thus:

 ds.Tables["cantas_apagar"].DefaultView.RowFilter = "(vencimento >= #" + txtDataInicial.Text + " # and vencimento <= #" + txtDataFinal.Text + "#)";
                    GridView1.DataBind();

If anyone has any ideas, thank you. Thank you.

1 answer

1


I was able to solve the problem, actually it was not on the dates, but because the grid was not being loaded when I was going to perform the filter, I put to load before calling the method on the search button, and it worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.