Dynamic field RRS feed

  • Question

  • User-944089421 posted

    I have a DetailsView with a few DynamicFields, bound to a LinqDataSource and the DefaultMode is set to Insert on the DetailsView.

    What I want to do is initialise one of the textboxes with a value the user will not have to enter on the webpage.

    What would seem like a simple thing to do, appears otherwise.  I'm struggling with this now.

    Can anyone tell me how I can set this value, either imperatively or declaratively.

    Thanks very much.


    Friday, October 24, 2008 8:18 AM

All replies

  • User1024101778 posted


    Check this thread out.


    The code snippet I believe you are looking for is:

    protected void DetailsView1_PreRender(object sender, EventArgs e)
    	string value = Session["FirstName"].ToString();
    	if (!string.IsNullOrEmpty(value))
    		var ftuc = DetailsView1.FindFieldTemplate("FirstName") as FieldTemplateUserControl;
    		if (ftuc != null)
    			var tb = ftuc.DataControl as TextBox;
    			tb.Text = value;
    			tb.Enabled = false;
    Friday, October 24, 2008 10:03 AM
  • User-330204900 posted

    var ftuc = DetailsView1.FindFieldTemplate("FirstName") as FieldTemplateUserControl;

    Note Gavin that the DetailsView1.FindFieldTemplate("FirstName") is the name of the field/column name not the control Id.

    Just thought is was worth mentioning [:D]

    Friday, October 24, 2008 11:17 AM
  • User1806792307 posted

    In your metadata class, use the DefaultValueAttribute(). It is applied when using Insert mode.

    [DefaultValue("My Text")]
    public object LastName { get; set; }

    Friday, October 24, 2008 2:18 PM