Monday, May 17, 2010

Dropdownlist in a Gridview and the default (null) value problem

The problems come if the data in the table doesnt fit your data in the PLZ table. Most common reason is that the field contains a NULL Value. Bind fails!

The trick is that you can add items to the dropdown list by declaration. The second part of the trick is to add the DB entrys to the declarated entrys by AppenddataboundItems. Take care to set the value to "" cause the bind gives also back a "" if the field contains NULL


;<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="DSPLZ" DataTextField="PLZ"

DataValueField="PLZ" SelectedValue=';<%# Bind("shipPLZ") %;>' AppendDataBoundItems=true;>

;<asp:ListItem Text="wählen" Value="";></asp:ListItem;>

;</asp:DropDownList;>



;</asp:TemplateField;>

No comments:

Post a Comment