I’m trying to populate a date from a bound text field in a DetailsView. I keep getting a error when a DBNull is in the column. How do I avoid the DBNull when populating the text field. Any Help on this would be great at a loss.
My code is as follows:
<asp:TemplateField HeaderText="CBYD Clear Date">
<EditItemTemplate>
<asp:TextBox ID="CBYDExpDate" runat="server" ReadOnly="true" Text='<%# IIf(Eval("CBYDDate") is DBNull.Value,"", String.Format("{0:MM/dd/yyyy}", Eval("CBYDDate").AddDays(30)))%>' />
</EditItemTemplate>
</asp:TemplateField>
The simpliest would be to define a function in codebehind that you call:
and in codebehind:
For additional informations have a look at MSDN