Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,293 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,108 people online right now. Registration is fast and FREE... Join Now!




DropDownLIst and enum

 
Reply to this topicStart new topic

DropDownLIst and enum, problems with drop down list

cindynelson
post 23 Sep, 2008 - 12:56 PM
Post #1


New D.I.C Head

*
Joined: 22 Sep, 2008
Posts: 1

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 => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:25AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month