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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownlist problem

Status
Not open for further replies.

cyrus71

Programmer
Feb 6, 2006
34
SE
Hi, I have been working with my project for 2 weeks but i have failed everytime, The problem is i want to catch the selecteditem in my dropdownlist but it is just the first item everytime,
here is my code:
protected override void CreateChildControls()
{
DDL = new DropDownList();
DDL.Load += new EventHandler(DDLLoad);
DDL.SelectedIndexChanged += new EventHandler(DDLItemChanged);
Controls.Add(DDL);
}
protected void DDLLoad(object sender, EventArgs e)
{
DS = GetChannels();
if (DS.Tables.Count > 0 )
{
DDL.DataSource = DS;
DDL.DataTextField = "title";
DDL.DataValueField = "title";
DDL.DataBind();

}
else
{
MessageLBL.Text = "Unable to connect to the database.";
}
}
protected void DDLItemChanged(object sender, EventArgs e)
{
string mytitle = DDL.SelectedValue;

MessageLBL.Text = mytitle; //here it is always the first item
}
 
Set a breakpoint on

string mytitle = DDL.SelectedValue;

and see how many items are actually contained in the dropdown. Then check to see what the SelectedIndex is.

Does EventArgs e have a new index? I can't remember.

e.NewIndex?

Regardless, it shouldn't always be the first item in the list.
 
thank you,
i have checked and there is more than one items are contained in the dropdownlist,
actually it is the first item,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top