Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have dropdownlist. In dropdown has different options. when i have selected dropdown to display data in gridview.

My problem is frequently i'm selecting dropdown gridview previously data its showing.

How to clear data in gridview..
Posted
Comments
Prabhakaran Soundarapandian 7-Aug-12 8:25am    
If you want a clear solution means show your code...
bbirajdar 7-Aug-12 8:37am    
Right.. :)
balongi 23-Feb-15 4:48am    
bind with null as datasource

Clear your dataSet after binding of Gridview.

C#
GridView1.Datasource=ds;
GridView1.Databind();
ds.Clear();



Thanks
AShish
 
Share this answer
 
Set the DataSource of GridView to null on SelectedIndexChanged event of your DropDownList and then call your GridView Binding function.
C#
Gridview1.DataSource = null;
Gridview1.DataBind();
fnBindGrid(ddlTest.SelectedValue);
private void fnBindGrid(string str){
    //bind your gridview here.
}





--Amit
 
Share this answer
 
Comments
Member 15088142 3-Mar-21 6:14am    
private void cmbServer_SelectedIndexChanged(object sender, EventArgs e)
{
LicenseAllctnGridView.Rows.Clear();
LicenseAllctnGridView.Columns.Clear();
LicenseAllctnGridView.DataSource = objDBIO.ImportLicenseUsageDataFromDB(DBPath);
((DataTable)LicenseAllctnGridView.DataSource).DefaultView.RowFilter = $"Server Like '{cmbServer.SelectedItem.ToString()}%'";
this.LicenseAllctnGridView.Columns["Server"].Visible = false;
// LicenseAllctnGridView.Rows.Clear();
}
If you change the data of gridview whenever you change the dropdownlist item means...in your dropdown selection changed event add
C#
Gridview1.DataBind();
 
Share this answer
 
Use this code where you want to clear it

C#
Gridview1.DataSource = null;
       Gridview1.DataBind();
 
Share this answer
 
Comments
kumar2233 7-Aug-12 8:14am    
i try but. in dropdown different 5 options are their. i select any option to display data in gridview. but i select another option previous data its showing. so Gridview data is not clear.
bbirajdar 7-Aug-12 8:37am    
Show your code...If you expect to get a exact reply and if you really want to solve the problem..How can I guess what code you have written ?
kumar2233 8-Aug-12 0:50am    
i'm using asp.net and vb.net
..............................

Protected Sub dropdownlist1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles

ui_ddl_Reports.SelectedIndexChanged
dropdownlist1.datasource= ds
dropdownlist1.databind()

gridview1.datasource=nothing
gridview1.databind()


End
bbirajdar 8-Aug-12 2:55am    
Here the mistake is...

Put this code is Page_Load
dropdownlist1.datasource= ds
dropdownlist1.databind()

And the rest will work...

next time You should show your code first if you want a quick answer..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900