Non mi sono ancora avventurato in questo controllo, ma, prova e riprova, si piò fare pure così:
codice:
Private vuoto As Boolean = False
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = Libreria.GetDataTable(Global.ASP.global_asax.StringaConnessioneTest, "SELECT TOP 5 * FROM CAMPI WHERE 1=1")
Me.GridView1.DataSource = dt
Me.vuoto = dt.Rows.Count = 0
Me.GridView1.DataKeyNames = New String() {"id"}
Me.GridView1.DataBind()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dt As DataTable = Libreria.GetDataTable(Global.ASP.global_asax.StringaConnessioneTest, "SELECT * FROM CAMPI WHERE 1=0")
Me.vuoto = dt.Rows.Count = 0
Dim r As DataRow = dt.NewRow()
r(0) = 0
dt.Rows.Add(r)
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If Not Me.vuoto Then Exit Sub
Select Case e.Row.RowType
Case DataControlRowType.DataRow
e.Row.Visible = False
End Select
End Sub