Okay, I have a FormView with a couple of child controls in an InsertItemTemplate. One of them is a DropDownList, called DdlAssigned. I reference it in the Page’s OnLoad method like so:
protected void Page_Load(object sender, EventArgs e) { ((DropDownList)FrmAdd.FindControl('DdlAssigned')).SelectedValue = ((Guid)Membership.GetUser().ProviderUserKey).ToString(); }
Basically I’m just setting the default value of the DropDownList to the user currently logged in.
Anyway, when the page finishes loading the SelectedValue change isn’t reflected on the page. I stepped through OnLoad and I can see the change reflected in my Watch list, but when all is said and done nothing’s different on the page.
I figured it out. I’m still missing exactly why it doesn’t work just on FormLoad, but performing the change in the FormView’s DataBound event does the trick.
So, I guess the general rule of thumb is that if you are having problems making changes to controls when working with databinding, try to make them immediately after it has been bound.