Megosztás a következőn keresztül:


Handling Null Database Values Using Data Source Controls

This topic Handling Null Database Values Using Data Source Controls has now been updated on MSDN to fix the sample based on various customer feedback. You can still see the old version here, in case you're curious to compare both versions.

What has changed:

  • In the previous sample, the two-way data-binding was not in place, so editing was not working. If you noticed that and tried to replace the Eval() statement by a Bind() statement in the EditItemTemplate, it wouldn't work either. Bind() statements don't support being encapsulated by other method calls as Eval() statements do. (A good explanation for that can be found in Eilon's blog).
  • The previous sample was already using a great technique for handling null values, the AppendDataBoundItems property was set to true in the DropDownList control. The AppendDataBoundItems property enables you to populate the DropDownList control with both static items and data generated from the data source. However, the value for the null entry was set to zero. So every time a null value was read from the database, it had to be converted to zero. Changing the item list to an empty value did the trick here. The empty value is now automatically converted to null without the need to use a function for that (because the ConvertEmptyStringtoNull property of both the TemplateField and the data source control parameter is set to true).

Take a look and let us know if you think this has improved or if you still think it needs some work!