Dim ds as DataSet = Nothing
ds = 'Query Data มาใส่ที่นี่
'Call the Sub: gv is the GridView I have designed in the form designer.
BuildNoRecords(gv, ds)
Code (VB.NET)
Public Sub BuildNoRecords(ByVal gridView as GridView, ByVal ds as DataSet)
Try
If ds.Tables(0).Rows.Count = 0 Then
'Add a blank row to the dataset
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow())
'Bind the DataSet to the GridView
gridView.DataSource = ds
gridView.DataBind()
'Get the number of columns to know what the Column Span should be
Dim columnCount as Integer = gridView.Rows(0).Cells.Count
'Call the clear method to clear out any controls that you use in the columns. I use a dropdown list in one of the column so this was necessary.
gridView.Rows(0).Cells.Clear()
gridView.Rows(0).Cells.Add(New TableCell)
gridView.Rows(0).Cells(0).ColumnSpan = columnCount
gridView.Rows(0).Cells(0).Text = "No Records Found."
End If
Catch ex as Exception
'Do your exception handling here
End Try
End Sub