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

  • SEARCH
  • Home
  • 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 4571456
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:30:24+00:00 2026-05-21T19:30:24+00:00

I want to put the current date in my formview ‘dateadded’ but its not

  • 0

I want to put the current date in my formview ‘dateadded’ but its not showing when I load it in the browser. I’m using code behind but how can I display it with date and time?

Here’s a my code behind.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace LibrarySystem.AdminPage
{
    public partial class ManageBooks : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(FormView1.CurrentMode == FormViewMode.Insert)
            {
                TextBox dateadded = FormView1.FindControl("dateaddedTextBox") as TextBox;
                    dateadded.Text = DateTime.Now.ToString("d");
            }
        }
    }
}

Here’s my complete design

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Lending.aspx.cs" Inherits="LibrarySystem.Test" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h3>
    Lending of Books</h3>
<p>
    <asp:FormView ID="FormView1" runat="server" DataSourceID="lendDataSource" DefaultMode="Insert" OnDataBound="FormView1_DataBound">
        <EditItemTemplate>

            Book ID/ISBN:
            <asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
            <br />

            Book Title:
            <asp:TextBox ID="booktitleTextBox" runat="server" 
                Text='<%# Bind("booktitle") %>' />
            <br />

            Employee ID:
            <asp:TextBox ID="employeeidTextBox" runat="server" 
                Text='<%# Bind("employeeid") %>' />
            <br />

            Department:
            <asp:TextBox ID="departmentTextBox" runat="server" 
                Text='<%# Bind("department") %>' />
            <br />

            Date borrowed:
            <asp:TextBox ID="dateborrowedTextBox" runat="server" 
                Text='<%# Bind("dateborrowed") %>' />
            <br />

            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>

        <InsertItemTemplate>

            Book:
            <asp:DropDownList ID="DropDownList1" runat="server" 
                DataSourceID="booktitleDataSource" DataTextField="booktitle" 
                DataValueField="bookid" SelectedValue='<%# Bind("bookid", "{0}") %>'>
            </asp:DropDownList>

            <asp:SqlDataSource ID="booktitleDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
                SelectCommand="SELECT [bookid], [booktitle] FROM [TblBooks]">
            </asp:SqlDataSource>
            <br />

            Employee ID:
            <asp:TextBox ID="employeeidTextBox" runat="server" 
                Text='<%# Bind("employeeid") %>' />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* Required" ControlToValidate="employeeidTextBox" ValidationGroup="lendbook">
            </asp:RequiredFieldValidator>
            <br />

            Department:
            <asp:TextBox ID="departmentTextBox" runat="server" 
                Text='<%# Bind("department") %>' />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required" ControlToValidate="departmentTextBox" ValidationGroup="lendbook">
            </asp:RequiredFieldValidator>
            <br />

            Date borrowed:
            <asp:TextBox ID="dateborrowedTextBox" runat="server" 
                Text='<%# Bind("dateborrowed") %>' />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="* Required" ControlToValidate="dateborrowedTextBox" ValidationGroup="lendbook">
            </asp:RequiredFieldValidator>
            <br />

            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"  ValidationGroup="lendbook" 
                CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" 
                CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>

        <ItemTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="New" />
        </ItemTemplate>

        <EmptyDataTemplate>
            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                CommandName="New" Text="New" />
        </EmptyDataTemplate>
    </asp:FormView>
</p>
    <p>
    <asp:SqlDataSource ID="lendDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
        DeleteCommand="DELETE FROM [LendTable] WHERE [lenid] = @lenid" 
        InsertCommand="INSERT INTO [LendTable] ([bookid], [employeeid], [department], [dateborrowed], [datereturned]) VALUES (@bookid, @employeeid, @department, @dateborrowed, @datereturned)" 
        SelectCommand="SELECT dbo.LendTable.bookid, dbo.TblBooks.booktitle, dbo.LendTable.employeeid, dbo.LendTable.department, dbo.LendTable.dateborrowed FROM dbo.LendTable INNER JOIN dbo.TblBooks ON dbo.LendTable.bookid = dbo.TblBooks.bookid" 

        UpdateCommand="UPDATE [LendTable] SET [bookid] = @bookid, [employeeid] = @employeeid, [department] = @department, [dateborrowed] = @dateborrowed, [datereturned] = @datereturned WHERE [lenid] = @lenid">
        <DeleteParameters>
            <asp:Parameter Name="lenid" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="bookid" Type="Int64" />
            <asp:Parameter Name="employeeid" Type="string" />
            <asp:Parameter Name="department" Type="String" />
            <asp:Parameter Name="dateborrowed" Type="DateTime" />
            <asp:Parameter Name="datereturned" Type="DateTime" />
            <asp:Parameter Name="lenid" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="bookid" Type="Int64" />
            <asp:Parameter Name="employeeid" Type="string" />
            <asp:Parameter Name="department" Type="String" />
            <asp:Parameter Name="dateborrowed" Type="DateTime" />
            <asp:Parameter Name="datereturned" Type="DateTime" />
        </InsertParameters>
    </asp:SqlDataSource>
</p>
<p>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
        DataKeyNames="lenid" DataSourceID="lendgridviewDataSource" ForeColor="#333333" 
        GridLines="None">
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="bookid" HeaderText="Book ID/ISBN" 
                SortExpression="bookid" />
            <asp:BoundField DataField="booktitle" HeaderText="Book Title" 
                SortExpression="booktitle" />
            <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" 
                SortExpression="EmployeeID" />
            <asp:BoundField DataField="department" HeaderText="Department" 
                SortExpression="department" />
            <asp:BoundField DataField="dateborrowed" HeaderText="Date Borrowed" 
                SortExpression="dateborrowed" />
            <asp:BoundField DataField="datereturned" HeaderText="Date Returned" 
                NullDisplayText="-- not yet returned --" SortExpression="datereturned" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:SqlDataSource ID="lendgridviewDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
        DeleteCommand="DELETE FROM [LendTable] WHERE [lenid] = @lenid" 
        InsertCommand="INSERT INTO [LendTable] ([bookid], [department], [EmployeeID], [dateborrowed], [datereturned]) VALUES (@bookid, @department, @EmployeeID, @dateborrowed, @datereturned)" 
        SelectCommand="SELECT dbo.LendTable.lenid, dbo.LendTable.bookid, dbo.LendTable.department, dbo.LendTable.EmployeeID, dbo.LendTable.dateborrowed, dbo.LendTable.datereturned, dbo.TblBooks.booktitle FROM dbo.LendTable INNER JOIN dbo.TblBooks ON dbo.LendTable.bookid = dbo.TblBooks.bookid" 
        UpdateCommand="UPDATE [LendTable] SET [bookid] = @bookid, [department] = @department, [EmployeeID] = @EmployeeID, [dateborrowed] = @dateborrowed, [datereturned] = @datereturned WHERE [lenid] = @lenid">
        <DeleteParameters>
            <asp:Parameter Name="lenid" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="bookid" Type="Int64" />
            <asp:Parameter Name="department" Type="String" />
            <asp:Parameter Name="EmployeeID" Type="String" />
            <asp:Parameter Name="dateborrowed" Type="DateTime" />
            <asp:Parameter Name="datereturned" Type="DateTime" />
            <asp:Parameter Name="lenid" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="bookid" Type="Int64" />
            <asp:Parameter Name="department" Type="String" />
            <asp:Parameter Name="EmployeeID" Type="String" />
            <asp:Parameter Name="dateborrowed" Type="DateTime" />
            <asp:Parameter Name="datereturned" Type="DateTime" />
        </InsertParameters>
    </asp:SqlDataSource>
</p>
<p>
    <asp:HyperLink ID="HyperLink4" runat="server" 
        NavigateUrl="~/Admin/Returning.aspx">Returning</asp:HyperLink>
</p>
        <asp:HyperLink ID="HyperLink5" runat="server" 
            NavigateUrl="~/Admin/AdminPage.aspx">Back to Admin Page</asp:HyperLink>
    <p>
        &nbsp;</p>

    </asp:Content>
  • 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-05-21T19:30:24+00:00Added an answer on May 21, 2026 at 7:30 pm

    You have to use the Databound event for that…

     protected void FormView1_DataBound(object sender, EventArgs e)
    {
        if (FormView1.CurrentMode == FormViewMode.Insert)
        {
            TextBox dateadded = FormView1.FindControl("dateaddedTextBox") as TextBox;
            dateadded.Text = DateTime.Now.ToString("d");
        }
    }
    

    Edit: You need to pass your Date Column in the inserting method of the DetailsView

    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["DateColumnName"] = ((TextBox)DetailsView1.FindControl("dateaddedTextBox")).Text;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple query where I want to put the current date var
I want to insert the current date/time into my xml feed using Rails Builder.
I want to put the current date and time in the footer of my
Within c#, i can put data to seperate strings. For example the current date
I want put a button on android edittextpreference. I create a custom editextpreference: public
I've projected an Intranet Ajax application and I want put it in a full
hey, hi i want put limit on object creation means a class can have
I want to put two side by side on another (I have three )
I want to put some images in an area at the application start. As
I want to put the name of the loggedin user as the title of

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.