[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Pre populating a formview textbox in asp2.0

Posted on 2006-06-05
Medium Priority
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

deanvanrooyen earned 2000 total points
ID: 16840662

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


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 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