LittlBUGer
Programmer
Hello. I've been struggling with an issue where I have a gridview, bound to a SQL table, where I have one column as a template column so I can put in a dropdownlist in the gridview's edit mode for that column. I've gotten all of this to work great, except for when data coming from the database is NULL for that column. Nothing I've tried has gotten around it.
So the DDL in the gridview is getting data from the DB such as:
Text, Value
-----------
Text1, 1
Text2, 2
Text3, 3
Text4, 4
So the DDL text field is the Text column while the value field is the Value column--simple enough. I then have a OnDataBound event for the DDL where I then insert a "-" into the 0 item. So now the DDL has the following data:
Text, Value
-----------
-, -
Text1, 1
Text2, 2
Text3, 3
Text4, 4
I also have the SelectedValue property set to something like:
so that when it goes into the Edit mode, it selects the current/correct value. For the Select part of the SQL query the gridview is bound to, if there's a Null value, I set both the text column and the value column to '-', so something like:
Now, like I said, everything works fine, even the drop down, unless the value in the database is null, in which it doesn't work and I can't figure out why. I've tried doing different things in different events, but nothing seems to work. Am I missing something obvious? Any suggestions please? Thank you.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
So the DDL in the gridview is getting data from the DB such as:
Text, Value
-----------
Text1, 1
Text2, 2
Text3, 3
Text4, 4
So the DDL text field is the Text column while the value field is the Value column--simple enough. I then have a OnDataBound event for the DDL where I then insert a "-" into the 0 item. So now the DDL has the following data:
Text, Value
-----------
-, -
Text1, 1
Text2, 2
Text3, 3
Text4, 4
I also have the SelectedValue property set to something like:
Code:
SelectedValue='<%# Bind("Value") %>'
so that when it goes into the Edit mode, it selects the current/correct value. For the Select part of the SQL query the gridview is bound to, if there's a Null value, I set both the text column and the value column to '-', so something like:
Code:
SELECT ..., CASE WHEN [Text] IS NULL THEN '-' ELSE [Text] END AS Text, CASE WHEN [Value] IS NULL THEN '-' ELSE [Value] END AS Value FROM [MyTable]
Now, like I said, everything works fine, even the drop down, unless the value in the database is null, in which it doesn't work and I can't figure out why. I've tried doing different things in different events, but nothing seems to work. Am I missing something obvious? Any suggestions please? Thank you.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein