Ok, the way this works is a bit confusing.
If you use auto generated column, OR YOU use databound fields, eg like this:
<asp:BoundField DataField="BookingDate" HeaderText="Book Date" />
Then of course you do NOT use FindControl, but in fact use the .Cells[] colleciton.
ONLY WHEN you use .Cells[] collection does the text value for a null return that " "
But, WHEN you use a textbox, label etc.? (and FindControl)?
Then a null does return a empty string.
eg this:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = ((Label)GridView1.SelectedRow.FindControl("txtBDate")).Text;
if (str == "")
{
TextBox1.Text = "blank value";
}
else
{
//TextBox1.Text = str;
TextBox1.Text = Convert.ToDateTime(str).ToString("yyyy-MM-dd");
}
}
So in fact, since you ARE using a templated field, then you test for "" for nulls. But you are correct that when the grid renders, asp.net DOES CONVERT nulls to that " " since some browsers will not render a table correct without a blank in that cell.
So:
For cells[], and a null? (yes nulls convert to HTML space). And YES you do test for that HTML space like (some value == " ".
For templated controls such as label, text box? The null value is a empty string.
So, test for "" and you should be fine. And yes, it is VERY easy to mess this up, since you might have some code, databound fields - they DO return that HTML blank space, but templated controls do not use the cells[] collection, and they don't return HTML spaces, but an real empty string for null values.
Regards, Albert D. Kallal (Access MVP 2003-2017) Edmonton, Alberta Canada