Hi
I am using an edit form template within a radgrid. My edit form template is used to update Customer records. One of the fields in my customer table is TitleID which is a foreign key to the Titles table. This table contains records such as Mr, Mrs Miss etc. The form template contains a drop down list of these titles which is populated from the database. The SelectedValue property of the dropdown list is set to the TitleID of the current record. This is achieved like so
This code works fine for automatic updates. However when i try to perform an insert I get an error binding to the drop down list
I understand what is causing this error. Naturally for an empty record the value for Bind("ContactTitleID") is an empty string whereas this is not one of the items in the drop down list of titles.
How can i overcome this whilst still performing automatic inserts and updates? I can populate the drop down list of titles and the selected value in the ItemDataBound event but then the SelectedValue property of the of the cboTitles dropdown list is not passed to the ContactTitleID field because this control is not bound to this field.
I think this problem is avoided in standard grids because they have different templates for inserts and updates.
Many thanks
I am using an edit form template within a radgrid. My edit form template is used to update Customer records. One of the fields in my customer table is TitleID which is a foreign key to the Titles table. This table contains records such as Mr, Mrs Miss etc. The form template contains a drop down list of these titles which is populated from the database. The SelectedValue property of the dropdown list is set to the TitleID of the current record. This is achieved like so
<asp:DropDownList ID="cboTitle" runat="server" DataTextField="Title" DataValueField="TitleID" SelectedValue='<%# Bind("ContactTitleID") %>' DataSource='<%# (GetTitles()) %>'> |
</asp:DropDownList><br /> |
This code works fine for automatic updates. However when i try to perform an insert I get an error binding to the drop down list
'cboTitle' has a SelectedValue which is invalid because it does not exist in the list of items. |
Parameter name: value |
I understand what is causing this error. Naturally for an empty record the value for Bind("ContactTitleID") is an empty string whereas this is not one of the items in the drop down list of titles.
How can i overcome this whilst still performing automatic inserts and updates? I can populate the drop down list of titles and the selected value in the ItemDataBound event but then the SelectedValue property of the of the cboTitles dropdown list is not passed to the ContactTitleID field because this control is not bound to this field.
I think this problem is avoided in standard grids because they have different templates for inserts and updates.
Many thanks