how to check if cell of gridview is empty?

B

Bart

Hi,

i need to check wether a cell of a gridview is empty or not. I did this:

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim log1 As String
log1 = GridView1.SelectedRow.Cells(1).Text
.....

If log1 = "" Then
Response.Write("empty")
else
Response.Write(log1)
end if
....


When log1 contains data, i get it in the response.write, but when the field
in the sql-database contains NULL or is empty (e.g. by a previous update
operation), i don't get the expected 'empty'. So log1 = "" is considered
as false.

I checked the length with this line: response.write(log1.length)

This gives the right length when data is present, but gives 6 when it's NULL
or empty !!

Is that the default length of the empty cell in a gridview? How to test when
that cell is empty? (i also tried with IsDbNull but doesn't work either).

Thanks
Bart
 
M

Mark Rae [MVP]

How to test when that cell is empty?

A quick View Source would have given you the answer...

When a bound GridView cell contains no data, ASP.NET fills it with  

Hence the length of 6...
 
B

Bart

Thanks

Mark Rae said:
A quick View Source would have given you the answer...

When a bound GridView cell contains no data, ASP.NET fills it with  

Hence the length of 6...
 

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,701
Latest member
XavierQ83

Latest Threads

Top