How to Reset a Gridview c# aspnet?

Asked

Viewed 318 times

0

I have two tables(Datatable) different and need to use them in the same Gridview. But when I call Gridview on the screen it always takes the value of the first table.

Does anyone know how to make a Gridview adapted to any consultation?

dt = info.RetornaInfo(x,y);
GdvInfo.DataSource = dt;
GdvInfo.DataBind();
  • Those DataTable has the same number of columns and are respective values and types!

  • Post also the example of two DataTable that are different so that the answers are drawn up according to them.

1 answer

2

You will need to set the DataSource as null and then clear the lines of the DataGridView.

GdvInfo.DataSource = null;
GdvInfo.Rows.Clear(); 

dt = info.RetornaInfo(x,y);
GdvInfo.DataSource = dt;
GdvInfo.DataBind();

Previous response removed.

  • This way ? public void CarregaGrid()
 {
GdvInfo.DataSource = null;
GdvInfo.Rows.Clear(); 
 
 dt = info.RetornaInfo(x, y);
 GdvInfo.DataSource = dt;
 GdvInfo.DataBind();

 }

  • No. The way it is in the answer.

  • When I try to put Gdvinfo.Row.Clear() it returns the following error:System.Web.UI.WebControls.Gridviewrowcollection' does not contain a Definition for 'Clear' and no Extension method 'Clear' Accepting a first argument of type 'System.Web.UI.WebControls.Gridviewrowcollection' could be found (are you Missing a using Directive or an Assembly Reference?)

  • Take that line there, I must have confused with Windows Forms.

  • No code error ,plus, the grid uses the information and structure of the previous table.

Browser other questions tagged

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