DataGrid bound to DataTable containing blanks returns  

J

John A Grandy

anyone know why this is ?



Imports System.Data

Imports System.Diagnostics

Public Class WebForm12

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents dg1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim dcc As DataColumnCollection

Dim dr As DataRow

Dim drc As DataRowCollection

Dim dt As DataTable

Try

If Not Page.IsPostBack Then

dt = New DataTable

dcc = dt.Columns

dcc.Add("Col1", GetType(String))

dcc.Add("Col2", GetType(String))

drc = dt.Rows

dr = dt.NewRow

dr(0) = "abcd"

'dr(1) = ""

drc.Add(dr)

dr = dt.NewRow

dr(0) = "efgh"

'dr(1) = ""

drc.Add(dr)

dg1.DataSource = dt.DefaultView

dg1.DataBind()

End If

Catch ex As Exception

Debug.WriteLine(ex.Source & " " & ex.Message)

Finally

End Try

End Sub



Public Sub dg1_ItemCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

Dim dgi As DataGridItem

Dim s As String

Dim s1 As String

Try

dg1.SelectedIndex = e.Item.ItemIndex

dgi = dg1.SelectedItem

s = dgi.Cells(1).Text

'Debug mode mouse-over reveals s = "&nbsp;"

s1 = Trim(Server.HtmlDecode(s))



Catch ex As Exception

Debug.WriteLine(ex.Source & " " & ex.Message)

Finally

End Try

End Sub



End Class
 
D

Dan Bass

John,

I suppose it could be that if you have a 2x2 table for example written as

<TABLE>
<TR>
<TD>
Cell 1:1
</TD>
<TD>
</TD>
</TR>
<TR>
<TD>
</TD>
<TD>
</TD>
</TR>
</TABLE>

you'll not see the individual emtpy cells in this table. But if you insert a
space (&nbsp;) into each cell, then you'll be able to see the borders around
each cell in the grid affect... To see my point, create a new HTML file
which contains one table where the empty cells really are empty, and where
the empty cells have a "&nbsp;" spacer.

The fact is that a datagrid gets rendered to the client as a table, so if
the empty cells didn't have these characters, the grid would look quite odd.

Thanks.

Dan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top