Is there a way to force a gridview to have no rows RRS feed

  • Question

  • User1909110561 posted

    I have a gridview on a form. It's datasource is one of many table populated by a stored procedure.  There is drop down that changes one parameters.  In most cases, the default parameter brings back records but in the 2nd option it very well could return no records. What I am seeing is that the datasource tables have no records but the gridview isn't rebinding. I have tried forcing the gridview to databind and it acts as if it does but the gridview returns the records from the first time though. Is there an attribute in a gridview I am missing where I can tell it the datasource returned empty?

    Thursday, September 28, 2017 5:46 PM

All replies

  • User475983607 posted

    The GridView has an empty data template that you can use to display a message like "No Records Found".  However, it sounds like you might a have bug in the code.  Try using the Visual studio debugger to step through the logic or post the relevant bits if you need help debugging.

    Thursday, September 28, 2017 6:06 PM
  • User-1812511197 posted

    This might help....

    I always set these 2 properties for a Gridview.

    ShowHeaderWhenEmpty="true" EmptyDataText="No Assests Found"

    Thursday, September 28, 2017 6:06 PM
  • User1909110561 posted

    OK,  there might be a misunderstanding. i am aware of the emptydatatext attribute.  

    Just as a test to debug I placed this code at the end of the  sub.

    If dsData.Tables(7).Rows.Count = 0 Then
    gv.Visible = False
    End If

    When debugging, I see the count is zero and it says it sets the gridview to invisible but when the page renders, the gridview shows and it shows the original dataset values. Something is not getting set correctly.

    Thursday, September 28, 2017 7:29 PM
  • User409696431 posted

    We can't tell you what is happening, since you have showed no code.  But first, use Visual Studio's debugger to find out when the gridview is actually being bound with the data it is showing.  If you bind it to no data, and then it is subsequently, in the page cycle, bound to different values before the page is rendered, it would explain why you don't see what you expect., as one possibility.

    Thursday, September 28, 2017 7:54 PM
  • User-707554951 posted

    Hi  dotnetcoder99

    Only from your description, it is hard for us to find the reason for your problem.

    So, I suggest you could post related code of your problem so that we could reproduce your problem and find solution for you as soon as possible.

    Best regards


    Friday, September 29, 2017 5:56 AM