1

In a detailsview I have an extension of a dropdownlist server control that I have called ZZZZDropDown. The problem is that base.Items is empty at the time the extended server control gets called. So my logic fails as it requires the Items to have the data from the DataSourceId. I can confirm that, yes, there is data being returned from the query.

Here is the code for the DetailsView

<asp:DetailsView ID="ZZZZDV" runat="server" Width="100%" AutoGenerateRows="False" DataKeyNames="ZZZ" DataSourceID="ZZZDS">
    <Fields>
        <asp:TemplateField HeaderText="Assigned To" SortExpression="AssignedTo">
            <EditItemTemplate>
                <asp:ZZZZDropDown ID="DropDownList2" runat="server" DataSourceID="ZZZZDS" DataTextField="Employee" DataValueField="ZZZZEmpID" SelectedValue='<%# Bind("ZZZZEmployeeID") %>'>
                </asp:ZZZDropDown>
            </EditItemTemplate>

.......

Here is the code for Extended Server Control

public class ZZZZDropDown : DropDownList
{
    public override string SelectedValue
    {           
        get { return base.SelectedValue; }
        set
        {
            try
            {
                base.Items.FindByValue(value).Selected = true;
            }
            catch 
            {
                using (EntitiesModel ZZZZ = new EntitiesModel())
                {
                    var Emp = (from emp in ZZZ.ZZZZZ where emp.EmployeeID == value.ToInt() select emp).FirstOrDefault();
                    base.Items.Add(Emp != null ? new ListItem(Emp.ZZZZZZ + ", " + Emp.ZZZZZZ, value) : new ListItem("Archived Employee", value));
                }
                base.Items.FindByValue(value).Selected = true;
            }
        }
    }   

My question is how can I get the ListItemCollection of Items at the time of the running of the extended Server Control

Darren
  • 1,352
  • 5
  • 19
  • 49

0 Answers0