Controls of a template are created dynamically when the template is shown, trying to get a reference to these controls in the typical way will lead to a null reference exception.
Thus, the way to get a reference to a control in a template is using the FindControl method, which looks for controls within the current naming container by its Id
Now suppose that you want to update some controls when the user switches from one FormViewMode to another. For example, you may want to get a DropDownList filled with data when entering Edit mode. At first you may think that handling the ModeChanged event of the FormView is the correct solution.
Sub EmployeeFormView_DataBound(ByVal sender As Object, ByVal e As EventArgs) If myFormView.CurrentMode = FormViewMode.Edit Then Dim countries As DropDownList = CType(myFormView.FindControl("countriesDropDownList"), DropDownList) If countries IsNot Nothing Then ' fill the dropdownlist with data End If End If End Sub
|
No responses found. Be the first to respond and make money from revenue sharing program.
|