setting label to visible with button click

Last post 02-27-2007 2:13 PM by tomosap. 2 replies.

Sort Posts:

  • setting label to visible with button click

    02-27-2007, 12:03 PM
    • Loading...
    • tomosap
    • Joined on 02-19-2007, 5:18 PM
    • Wales, United Kingdom
    • Posts 15

    Hi,

    I'm having some problems with using a label to display a message "No Records Found" when the user clicks a Search button. What I want it to do is to check if there are any results from a database that get displayed on a GridView. I have the following method so far:

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        Protected Sub SearchBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
            If GridView1.Rows.Count = 0 Then

                NoRecords.Visible = True

            Else
                NoRecords.Visible = False
                GridView1.DataBind()
            End If
        End Sub

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

    GridView1 is self explanatory, and "NoRecords" is the ID of the label. I initially set it to false in the properties in the default.aspx page, and what I want to do is:

    • when the page loads, label doesn't display all
    • if the user enters a search and it returns a result and the gridview displays and has more than 0 rows, then the label stays invisible
    • if the user enters a search and it can't find anything, then set the label to visible with the message desired.
    • If the user then enters another search which gives more than 0 results, make the label disappear again.

    Can anyone help as this is driving me a little mad! Smile

    Thanks,

    Tom 

     

  • Re: setting label to visible with button click

    02-27-2007, 1:03 PM
    Answer
    • Loading...
    • AjaxButter
    • Joined on 01-29-2007, 8:45 PM
    • Louisville, Colorado
    • Posts 130

    It seems like you have it mostly correct the only thing i can see that may need to change is to move the databind before you check the length of the gridview so it is loaded with the results of the bind then you can see if its empty.  Other then that if its in an update panel then make sure you call the .Update() method of the updatepanel.

    AjaxButter

  • Re: setting label to visible with button click

    02-27-2007, 2:13 PM
    • Loading...
    • tomosap
    • Joined on 02-19-2007, 5:18 PM
    • Wales, United Kingdom
    • Posts 15

    Awesome!!!

    Cheers for that,

    Tom

Page 1 of 1 (3 items)
Microsoft Communities
Page view counter