Walaa wrote:
There is a place, you need to do the following:
<asp:dropdownlist id="ddlServiceType" runat="server" SelectedValue='<%# Bind("YourField")%>' />
OK... If I change my .aspx to use...
<asp:dropdownlist id="ddlServiceType" runat="server" SelectedValue='<%# Bind("ServiceTypeID")%>' />
I get the following .NET error...
'ddlServiceType' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
This is because I currently fill my drop down list when my FormView is DataBound and it tries to bind it before it's getting filled.
So I moved my code to fill my drop down, to a protected sub, called when that drop down is initialized.
<asp:dropdownlist id="ddlServiceType" runat="server" oninit="ddlServiceType_onInit" SelectedValue='<%# Bind("ServiceTypeID")%>' />
Protected Sub ddlServiceType_onInit(ByVal sender As Object, ByVal e As System.EventArgs)
'Bind Service Type
Dim refServiceType As New InspectionServiceTypeCollection
refServiceType.GetMulti(Nothing)
Dim ddlServiceType As DropDownList = CType(sender, DropDownList)
ddlServiceType.DataSource = refServiceType
ddlServiceType.DataTextField = "Description"
ddlServiceType.DataValueField = "ID"
ddlServiceType.DataBind()
End Sub
It fires the onInit, but the binding of the list values seems to trigger the Bind() in the aspx page. Now I get the following error...
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
The bottom line is that I want to fill a drop down list from my Service Type Collection and then bind the selected value to the Inspection Entity being retrieved.