Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

DetailsView Date on Insert

I have a DetailsView with a textbox in my insertitemtemplate that when I click the Insert link, I want it to get the Now() date as the default on the insert form.

I have set this up, so that it retrieves the Now() date

         <asp:TextBox ID="TextBox1" runat="server" Text='<%# CurrentDate()%>'></asp:TextBox>

It then goes to this function in the codebehind to get the date:

    Protected Function CurrentDate() As Date
        CurrentDate = Now()
    End Function

On save, it's not saving the date though. It saves a null value.

How do I tell it to save it to the "mydate" field? It used to have Text='<%# Bind("mydate") %>'

How do I bind it so that it knows to save the populated date to the mydate field?


Avatar of atastec

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Starr Duskk


That almost works. I have an EditItemTemplate and an ItemTemplate and of course the bind text box doesn't exist in the ItemTemplate, because it's just a label, so I added the TextBox to the ItemTemplate and made it not visible.

But on the EditItemTemplate, it overwrites the value from the database with the Now() value. I only want to do this for the InsertItemTemplate.
... so is there a way of specifying to only do this for the InsertItemTemplate?

I have decided to go a different route with this. I would like to have the value within the field prior to pressing the submit button, but since I can't get it to work for the other 2 templats, I am going to do this, and I can just leave the field empty if I want today's date as default:

    Protected Sub ObjectDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Inserting
        e.InputParameters("CurrentDate") = Now()
    End Sub