Pre populating a formview textbox in asp2.0

Posted on 2006-06-05
Last Modified: 2008-02-07
New to programming and I’m looking for a sample in C#, of how to Pre-populate a formview control textbox in insert mode (ASP 2.0)

I have a formview control with a date field, and Name field, i would like to be pre- populated with the current date the name from a dropdown listbox.
Question by:bmanmike39
    1 Comment
    LVL 12

    Accepted Solution


    1 - at the top of the aspx page below the header put this in <%@ Import Namespace="System" %>

    <%@ Page Language="C#" .....
    <%@ Import Namespace="System" %>

    now you can use datetime object in the aspx page

    in the inserttemplate
          <asp:Label ID="date" runat="server" Text='<%# DateTime.Now.ToString("yyyyMMdd HH:mm:ss") %>'></asp:Label>
    side note - you can format the date string to match format of db for datetime
              <asp:DropDownList ID="droplist" runat="server" DataSource='<%# GetNames() %>' DataTextField="xname" ></asp:DropDownList>
    side note - the datasource of the droplist is actually a method here, we define it in the code behind, the DataTextField is the column returned by the sql that holds the name, return a datatable in the method for ease of use

    in the page .cs file

        protected DataTable GetNames()
            string MySqlConnectionString = "server=localhost;user id=xxx; password=xxx; database=REO; pooling=false";
            MySqlConnection accessConnection = new MySqlConnection(MySqlConnectionString);
            MySqlCommand cmd = new MySqlCommand("select concat(name,' ',lastname) as xname from employee;", accessConnection);
            MySqlDataAdapter da = new MySqlDataAdapter();

            da.SelectCommand = cmd;

            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            return table;

    the drop list is populated with the name and lastname as defined in my sql...
    good luck


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now