Default Values on DetailsView Insert

asp.net, asp.net-membership, c#, data-binding

Solution

You can do this:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DetailsView1.DefaultMode = DetailsViewMode.Insert;
            if (DetailsView1.FindControl("TextBox1") != null)
            {
                TextBox txt1 = (TextBox)DetailsView1.FindControl("TextBox1");
                txt1.Text = User.Identity.Name.ToString();
            }
        }
    }

Problem

When users go to a specified page, I have a DetailsView attached to a SqlDataSource and already setup in Insert mode. I'm essentially using it as a registration page for certain events. Rather than having the users type in their "UserName", I want that field to automatically populate based on that user already being logged in. Does anyone have any suggestions on how to either have the User.Identity.Name be the default value that appears on Page_load, or how to code an override on DetailsViewInsertEventArgs? Of course, if I'm totally off-base, then other suggestions would be great. I'm using c# code behind. Thanks, Mike

Original source