pavkata wrote:
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox0" runat="server" CssClass="BigField" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqTitle" ControlToValidate="TextBox0" runat="server"
ErrorMessage="*" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Based On" SortExpression="">
<EditItemTemplate>
<asp:DropDownList ID="ddBasedOn" runat="server" SelectedValue='<%# Bind("EvaluationTemplateID") %>' DataSourceID="dsEvaluationTemplate" DataTextField="Title" DataValueField="ID" AppendDataBoundItems="True">
<asp:ListItem Value="" Text="*** Not based on template ***"/>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
I have two issues:
- On save, if the textbox is empty the value won't be saved as null in the database. I figured a workaround in my code by implementing the ItemUpdating event which seems to do trick. Without the code below, the value in the DB will not change from original value... what am I doing wrong?
protected void dvObject_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
//if value is null it does not get saved into the database for some reason
foreach (string key in e.NewValues.Keys)
{
if (e.NewValues[key] == null)
e.NewValues[key] = "";
}
}
Do you have set up the FieldNamesKeepEmptyStringAsValue property for the datasource control, perhaps?
Also, I assume you use the latest build for the runtime libs?
- On save, if I select the empty value from the dropdown, e.NewValues["EvaluationTemplateID"] would be null (which is correct) but the null value does not get written to the DB and value remains unchanged from original value. what am I doing wrong?
The entity field EvaluationTemplateID, what's the value of that in the entity? Is it a nullable field?