Hi
Thanks i didn't think of that, i didn't realise "" would map to null, but i
supose it must. I got round it by adding:
UNION
SELECT NULL AS ComplaintTypeID, NULL AS ComplaintTypeDescription
to the Select statment in the SQL datasource and it seems to work well.
"Phillip Williams" wrote:
[color=blue]
> When you define the dropdownlist in your detailsView, try adding a static
> listitem with value ="" and use the AppendDataBoundItems property of the
> DropDownList
>
http://msdn2.microsoft.com/en-us/lib...ms(VS.80).aspx
>
> For example,
> <asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountries"
> SelectedValue='<%# Bind("Country")
> %>'>
> <asp:ListItem Value="">Not Set</asp:ListItem>
> </asp:DropDownList>
>
> --
> HTH,
> Phillip Williams
>
http://www.societopia.net
>
http://www.webswapp.com
>
>
> "clickon" wrote:
>[color=green]
> > I am using ASP.net 2.0 and trying to take advantage of the updated data
> > editing facilities provided through the SQLDataSource control and the
> > DetailsView control. The data is a record from a customer complaints table
> > and one of the fields on the DetailsView control is called ComplaintType.
> > The field is a template field and in insert mode and edit mode i have used a
> > DropDownList control bound to a set of keys and values in a ComplaintTypes
> > table and the SelectedValue is bound to the foreign key in the complaints
> > table that links to the complaint types table. The problem i am having is
> > that the way the complaints procedure works is that, the complaint comes in
> > by phone and the receptionist simply takes basic details like name address
> > and a text description of the complaint The complaint then gets passed to
> > the QA department who then assign it a complaint type among other things.
> > When the receptionist enters the initial data they simply do not get an
> > option to set the compaint type, it defaults to NULL and all is well.
> > However when someone from the QA dept. clicks a link to turn the DetailsView
> > control into edit mode, it generates a runtime error because the
> > SelectedValue property is bound to a field that is set to NULL and NULL isn't
> > an value in the dataset bound to the DataValueField property. This error is
> > iritating because all it means is that ASP.net is not able to determine which
> > item in the HMTL drop down list to set to "selected" but instead of doing the
> > sensible thing and just not setting anything and carrying on, it generates a
> > run time error. The only way round this i can think of is to set an item in
> > the ComplaintTypes table to "Not Set" and set this as the default value for
> > the foreign key in the complaints table. This works but is an inelegant
> > solution especialy as i want to give the QA department the ability to update
> > the complaint types table and if they delete the "Not Set" record it will
> > make the whole thing fall over, so i then have to make sure that they can't
> > do that. This problem also applies to a number of other fields that work in
> > exactly the same way so it is not just a one field problem. Is there a
> > better solution that i have missed out on. One that doesn't require there
> > to be a matching record in the foreign table for the each foreign key in the
> > local table, especially as all these foreign keys default to NULL.[/color][/color]