• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

how to clear the data in the GridView

Hi,

I have a asp.net page where i am using VB as the language

I am using gridview to populate data from the database.  I have a select botton in each row and on selectedindexchanged i am populating another gridview.

OnRowDatabound on gridview1 i am assigning the values of each row to the respective select button.

Now how do i clear the data from the gridview1.
NOTE: In gridview1 only the select button is visible which has the row values.
0
Shiva_Kumar
Asked:
Shiva_Kumar
  • 3
  • 2
1 Solution
 
GiftsonDJohnCommented:
Hi,

Just set the DataSource of GridView to null;

GridView1.DataSource=null;
GridView1.DataBind();

It will clear all the rows. Since it has no databindings the GridView1 will disappear from the page. If you want to retain the header of the gridview you have to clear the rows from the datasource and bind with the GridView
0
 
Shiva_KumarAuthor Commented:
Hi,

I have tried your suggestion it, didn't work.

what i notice is, it goes off as you mentioned for a flash and it comes back with all the data immediately.

any other suggestion?

Thanks
0
 
GiftsonDJohnCommented:
If it comes back, then you are binding data to the GridView again. Can you post the code?
0
 
Shiva_KumarAuthor Commented:
i have a ajax tab control and under each tabpanel i have 3 gridview.

Onload i am populating the data on the first gridview of all the tabpanel.

On datarowbound of all the grid view i am using the following code to replace the select button with the row data

Protected Sub Gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles ISSAVQuestionCategory.RowDataBound
        Dim row As GridViewRow = e.Row

        Dim selectCell As TableCell = row.Cells(0)
        If (selectCell.Controls.Count > 0) Then

            Dim selectControl As LinkButton = selectCell.Controls(0)
            If Not IsDBNull(selectControl) Then

                selectControl.Text = e.Row.Cells(1).Text
                e.Row.Cells(1).Visible = False

            End If
        End If
    End Sub

now when somebody clicks on the select button (the row data) it popluates the second gridview of that particular tabpanel.

now what i want is when somebody changes the tab it should remove the data from the second gridview of all the tabpanels, so i am using the the activetabchanged function of the tabcontainer to call a javascript which intrurn calls the following function to remove the second gridview of the tabpanel

Public Sub noteproduct(ByVal tabindex As Integer)
        If tabindex = 0 Then
            Product = "abc"
        ElseIf tabindex = 1 Then
            Product = "xyz"
me.Gridview2.datasource = nothing
me.Gridview2.databind()
 End Sub

=================================================================================

i am binding the data to gridview2 only once that is when somebody clicks on gridview1 - selectedindexchanged function

Hope this helps,
Thanks



0
 
Shiva_KumarAuthor Commented:
Hi,

You were right.  It was binding the data again.  

Thanks for you help.. the problem is fixed now.

Thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now