2

I have a basic ASP.NET Web Forms application.

I give the user the possibility to create the records by using a Web Form and to update them by using a DetailsView.

The web form stores the empty field on the TextBoxes as *empty strin*g in the DB correctly.

The DetailsView instead stores them as null fields in the DB.

Moreover in the DetailsView_ItemUpdated event if I check the e.newvalues and e.oldvalues arguments the corresponding fields are null as well (throwing an exception) that means the data are already sent as null to the server upon submit.

In the DetailsView I use templates and I set all Update parameters in the SQLDataSource as ConvertEmptyStringToNull="false".

SQLDataSource parameter:

<asp:Parameter Name="SHELF" Type="String" ConvertEmptyStringToNull="false"/>

DetailsView

 <asp:DetailsView runat="server" 
                    ID="GvProductDetail" AutoGenerateRows="False" DataKeyNames="rowid" 
                    DataSourceID="ProductDetailData" 
                    OnItemUpdated="gvProductDetail_ItemUpdated">

 <asp:TemplateField>
    <HeaderTemplate>Stock Shelf &nbsp;</HeaderTemplate>
    <ItemTemplate>
       <%# Eval("Shelf") %>
    </ItemTemplate>
    <EditItemTemplate>
       <asp:TextBox runat="server" ID="txtShelf"  Text='<%# Bind("Shelf") %>' ></asp:TextBox>
    </EditItemTemplate>
</asp:TemplateField>

Is that possible that Bind converts the empty values to null? I thought it was enough to set the UpdateParameters rule not to convert empty string to null but apprently there is some other surprise. anybody might help?

Emmanuel N
  • 7,350
  • 2
  • 26
  • 36
CiccioMiami
  • 8,028
  • 32
  • 90
  • 151
  • You might find something from [this](http://stackoverflow.com/questions/2170021/convertemptystringtonull-false-and-yet-the-conversion-still-happens) related post – Emmanuel N Oct 26 '11 at 14:38
  • @EmmanuelN, thanks for your answer. I already had a look before at that post and it has no answer – CiccioMiami Oct 26 '11 at 14:59

1 Answers1

1

I solved it by placing ConvertEmptyStringToNull="false" to every <asp:TemplateField> containing <asp:TextBox>:

<asp:TemplateField ConvertEmptyStringToNull="false"> 
   <HeaderTemplate>Stock Shelf &nbsp;</HeaderTemplate> 
   <ItemTemplate>&nbsp;<%# Eval("Shelf") %></ItemTemplate> 
   <EditItemTemplate> 
     <asp:TextBox runat="server" ID="txtShelf" Text='<%# Bind("Shelf") %>' >
     </asp:TextBox> 
   </EditItemTemplate> 
</asp:TemplateField>
CiccioMiami
  • 8,028
  • 32
  • 90
  • 151