csharp
public enum formatItems
{
None = 0,
Scientific = 1,
FloatingPoint = 2,
Integer = 3,
Date = 4,
Time = 5,
DateTime = 6,
gpsLong = 7,
gpsLat = 8
}
// use List Collection from LoadEnums to populate dropdown
public void PopulateFormatDropDown(DropDownList ddl)
//public void PopulateFormatDropDown(DropDownList ddl, Enum formatList)
{
ddl.Items.Clear();
//create List<string> to hold the ddl items
List<string> csv = LoadEnumsforFormat();
// loop though all the items in the collection
// add each item to the list
for (int i = 0; i < csv.Count; i++)
{
ListItem item = new ListItem(csv[i].ToString());
ddl.Items.Insert(i, item);
}
//now we need to add a{Select One]" option at beginning of list
//ddl.Items.Insert(0, "[Select One]");
}
// Handle event when user changes scale selection
public void DropDownList1_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack == true)
{
DropDownList DropDownList1 = (DropDownList)Page.FindControl("DropDownList1");
DropDownList1.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
}
}
This is how I call it.
PopulateFormatDropDown(DropDownList3);This is the aspx code.
CODE
<asp:DropDownList ID="DropDownList1"
OnSelectedIndexChanged="DropDownList1_OnSelectedIndexChanged"
runat="server" AutoPostBack="true">
</asp:DropDownList>
The code above works as long as I manually populate the enum. Now I have a situation where I have to populate on the fly at runtime from an XML file. I am having the same problem with the dropdown that I had initially. The select does not work without the enum.
I tried this but it does not work.
This array from the XML file will populate the dropdown but it does not respond to the event.
csharp
string[] labels = definitionLabels.ToArray();
DropDownList DropDownList4 = (DropDownList)Page.FindControl("DropDownList4");
for (int j = 0; j < ((labels.Length) - 1); j++)
{
ListItem item = new ListItem(labels[j].ToString());
DropDownList4.Items.Insert(j,item);
}
The select reverts to the top of the dropdown list after the selection is made.
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder