Populating an ASP.Net DropDownList in a DetailsView from a typed DataSet

S_Assassin

New Member
We are trying to populate an ASP.Net DropDownList in a DetailsView with data from a strongly typed DataSet.In the debugger, ddlTheDropDownList does not have any value in it so we are assuming that FindControl is not locating DropDownListClass. Is DetailsView.DataBound the correct handler to use in order to populate the DropDownList ?Here is the markup section of the DropDownList:\[code\]<asp:TemplateField HeaderText="Class:" SortExpression="ClassID"> <EditItemTemplate> <asp:DropDownList ID="DropDownListClass" Runat="server"> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidatorEditDropDownListClass" runat="server" ControlToValidate="DropDownListClass" ErrorMessage="Please select a class." Font-Bold="True" Font-Italic="True" ForeColor="Red" SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator> </EditItemTemplate> <ItemTemplate> <asp:Literal ID="LiteralClass" runat="server" Text='<%# FormatAsMixedCase(Eval("ClassName").ToString())%>' /> </ItemTemplate> <ItemStyle ForeColor="Blue" /></asp:TemplateField>\[/code\]Here is the code-behind coding:\[code\]Protected Sub DetailsView_DataBound(sender As Object, e As EventArgs) Handles DetailsView.DataBound Dim theClassesTableAdapter As New DataSetClassesTableAdapters.ClassesTableAdapter Dim ddlTheDropDownList = DirectCast(FindControl("DropDownListClass"), DropDownList) ddlTheDropDownList.DataSource = theClassesTableAdapter.GetDataByAllClasses ddlTheDropDownList.DataTextField = "ClassName" ddlTheDropDownList.DataValueField = "ClassID" ddlTheDropDownList.SelectedValue = "http://stackoverflow.com/questions/13863069/ClassID" ddlTheDropDownList.DataBind()End Sub\[/code\]
 
Back
Top