Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList initial value

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
0
0
US
Hi,

I'm working on a web app that displays a couple of dropdownlists (ddl feed from an xml doc). When the app starts the 2 dropdown lists contain the 1st item of their respective lists. What I would like to do is have these values empty until the user makes a selection.

Depending on what the user selects for the first dropdownlist should dictate what options are available on the 2nd dropdownlist when clicked.

Here's my code:

Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;
using System.Text;

public partial class _Default : System.Web.UI.Page 
{
    private string xmlPath;


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) 
            {
                FillDropDown();
                FillDropDown2();
            }
    }

    private void FillDropDown()
    {
        this.selection.Items.Clear();
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load(xmlPath);
        XmlNodeList audienceList = xDoc.SelectNodes("/dataroot/List[not(Name=preceding-sibling::List/Name)]/Name");

        foreach (XmlNode n in audienceList)
        {
            ListItem item = new ListItem(n.InnerText, n.InnerText);
            this.selection.Items.Add(item);
        }
    }

    private void FillDropDown2()
    {
        this.selection2.Items.Clear();
        XmlDocument xDoc = new XmlDocument();
        xDoc.Load(xmlPath);
        XmlNodeList audienceList = xDoc.SelectNodes("/dataroot/List[not(Job=preceding-sibling::List/Job)]/Job");

        foreach (XmlNode n in audienceList)
        {
            ListItem item = new ListItem(n.InnerText, n.InnerText);
            this.selection2.Items.Add(item);
        }
    }
}


I would greatly appreciate it if someone can point out how to start the app with empty dropdownlists values. Thank you!
 
Thanks ca8msm. Your example worked!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top