Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9110835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:21:47+00:00 2026-06-17T03:21:47+00:00

Using this ASP.Net we would like to see today’s date appear in a date

  • 0

Using this ASP.Net we would like to see today’s date appear in a date Textbox when the user clicks the “New” button of a DetailsView so they can see the date in the Textbox prior to actually inserting the data.

<InsertParameters>
    <asp:Parameter Name="ClassID" Type="Int32" />
    <asp:Parameter Name="StudentID" Type="Int32" />
    <asp:Parameter Name="Absent" Type="String" />
    <asp:Parameter Name="Late" Type="String" />
    <asp:Parameter Name="LateTimeArrivedAtSchool" Type="DateTime" />
    <asp:Parameter DbType="Date" Name="DateAttendanceTaken"  DefaultValue= "<%=DateTime.Now.ToString() %>"/>
</InsertParameters>

I already tried to use DefaultValue = “<%=DateTime.Now.ToString() %>” but no date appears in the Textbox.

This is the markup for the textbox which is in the DetailsView:

<asp:TemplateField 
    HeaderText="Attendance Date:" SortExpression="DateAttendanceTaken">

    <EditItemTemplate>
        <asp:TextBox 
            ID="TextBoxDateAttendanceTaken" 
            runat="server" 
            Text='<%# Bind("DateAttendanceTaken", "{0:MM/dd/yyyy}") %>'>
        </asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidatorEditDate" runat="server" ControlToValidate="TextBoxDateAttendanceTaken" 
            ErrorMessage="Please enter the Attendance Date." Font-Bold="True" Font-Italic="True" ForeColor="Red" 
            SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>
    </EditItemTemplate>

    <InsertItemTemplate>
        <asp:TextBox 
            ID="TextBoxDateAttendanceTakenInsert" 
            runat="server" 
            Text='<%# Bind("DateAttendanceTaken", "{0:MM/dd/yyyy}") %>'>
        </asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidatorInsertDate" runat="server" ControlToValidate="TextBoxDateAttendanceTakenInsert" 
            ErrorMessage="Please enter the Attendance Date." Font-Bold="True" Font-Italic="True" ForeColor="Red" 
            SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>
    </InsertItemTemplate>

    <ItemTemplate>
        <asp:Label 
            ID="LabelDateAttendanceTaken" 
            runat="server" 
            Text='<%# Bind("DateAttendanceTaken", "{0:MM/dd/yyyy}") %>'>
        </asp:Label>
    </ItemTemplate>

    <ItemStyle ForeColor="Blue" />
</asp:TemplateField>

* UPDATE *

I found out that to get this to work, OnDataBinding needs to be added as shown here plus making sure there is a handler in the code-behind file as shown below.

InsertItemTemplate markup:

<InsertItemTemplate>
    <asp:TextBox 
        ID="TextBoxDateAttendanceTakenInsert" 
        runat="server" 
        Text='<%# Bind("DateAttendanceTaken", "{0:MM/dd/yyyy}") %>'
        OnDataBinding="TextBoxDateAttendanceTakenInsert_DataBinding">
    </asp:TextBox>

</InsertItemTemplate>

Handler in the code-behind file:

Protected Sub TextBoxDateAttendanceTakenInsert_DataBinding(sender As Object, e As EventArgs)

    Dim txtBox As New TextBox
    txtBox = DetailsView.FindControl("TextBoxDateAttendanceTakenInsert")
    txtBox.Text = DateTime.Now.ToString("d")
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:21:48+00:00Added an answer on June 17, 2026 at 3:21 am

    You can use the post back of the new button to set the textbox by grabbing the ListView’s insert item and finding the TextBoxDateAttendanceTakenInsert textbox.

    Set the value of the textbox to DateTime.Now.

    The Insert Item

    protected void NewButtonClick(object sender, EventArgs e)
    {
        //Code to change to set Insert
        //get insert item
        object control = MyDetailsView.FindControl("TextBoxDateAttendanceTaken")
        //check for null
        if(control != null){
            TextBox tBox = (TextBox)control; //cast to TextBox
            tBox.Text = DateTime.Now.ToString(); //set text
        }
    }
    

    VB:

    Dim tBox As TextBox =  CType(MyDetailsView.FindControl("TextBoxDateAttendanceTaken"), TextBox)
    tBox.Text = DateTime.Now.ToString
    

    That should do it, it just sets the textbox in the insert item to the current datetime each time new is clicked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
I have an ASP.NET MVC form laid out something like this: @using (Html.BeginForm(null, null,
I Need to make a webpage. asp.net this webpage recieve parameter by using Request.Querystring
So far, I'm doing this programmatically using VB.net/ASP.net: <table cellspacing=0 cellpadding=4 border=0 style=border- width:0px;width:100%;border-collapse:collapse;font-size:12px;>
I am using ASP.Net MVC but this probably applies to all MVC patterns in
This is a simple website in ASP.NET with C# using VS 2010. I have
This is my model of my asp.net mvc 2 project : using System; using
Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks
I am using ASP.NET Web Forms/C# . I am having this function in my
I am using ASP.net MVC with C#. Why this is code: public IQueryable<Product> ListProducts(string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.