Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net GridView IF empty show message

Tags:

asp.net

vb.net

I've got a grid view. I want it to say "you have nothing to show" if there are no details.

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound


    If GridView1.Rows.Count = 0 Then
        Lblemptygridview.Text = "you do no details to show"

    Elseif e.Row.RowType = DataControlRowType.DataRow then
        Dim datakey As String = GridView1.DataKeys(e.Row.RowIndex).Value.ToString()

    End If


End Sub

However; it seems to be working backwards and showing the message when there is data to display in the gird view and continues to be a blank page when there is not data to display in the grid view.

I've tried a variety of combinations with the below IF statement below but no success.

like image 955
user1055487 Avatar asked May 16 '26 05:05

user1055487


1 Answers

Instead, use the EmptyDataTemplate:

 <emptydatatemplate>
        No Data Found.  
    </emptydatatemplate> 
like image 144
Icarus Avatar answered May 18 '26 19:05

Icarus