How To Add Literal Values To A GridView Control?
Posted on 2006-06-01
I’m using cross joins to populate many GridView controls. My problem occurs when there is no data in the cross joins. The GridView is empty. I still need to report the data as follows:
How do I write code to add the data above to the GridView control?
The following code checks to see if the dataset is empty. If it is not empty then it populates the GridView Control. If it is empty, then I need to add some literal values to the GridView for reporting purposes.
Protected Sub btnLoadGrid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoadGrid.Click
Dim sCon As String
Dim sLoginID As String
Dim sPassword As String
Dim strSQL As String
sLoginID = "sa"
sPassword = "beatles"
strSQL = "Select * from vwStates"
sCon = "Data Source=beatles;Initial Catalog=Recruit;User Id=" & sLoginID & ";Password=" & sPassword & ";"
Dim da As New SqlDataAdapter(strSQL, sCon)
Dim ds As New DataSet
' Test to see if there is an empty dataset
If ds.Tables(0).Rows.Count = 0 Then
‘Add code to provide literal values to the grid
.DataSource = ds.Tables(0)