Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2004, 04:39 PM
Registered User
 
Join Date: Sep 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamically generated dropdownlist

Dear All;

I have a dynamically generated DropDownList, then I bind data from database to it. It displays the item correctly. But when I change the selected item and want to save the updated value, the selected item is always the first item, like ddl.SelectedIndex could not be changed.

 Does anyone have idea or it?

Thanks.

Chen

 
Old September 24th, 2004, 04:46 PM
Registered User
 
Join Date: Sep 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

code example:

protected override void CreateChildControls()
{
    _myDropDownList = new DropDownList();
    _myDropDownList.EnableViewState = true;

    //autoPostback or not does not help.
    _myDropDownList.AutoPostBack = false;
    _myDropDownList.SelectedIndexChanged += new EventHandler(_myDropDownList_SelectedIndexChanged) ;

DataBinding:
_myDropDownList.DataSource = dataTable.defaultView;
_myDropDownList.DataValueField = "col1";
_myDropDownList.DataTextField = "col2";
_myDropDownList.DataBind();
            }
Controls.Add(_myDropDownList);
}

private void _myDropDownList_SelectedIndexChanged(object sender, EventArgs e){
 selIndex = _myDropDownList.SelectedIndex;
ViewState["selectedIndex"] = selIndex;
}

selIndex = 0 always.

 
Old September 25th, 2004, 12:25 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Take a look at below link,it could help you in more detail
http://p2p.wrox.com/topic.asp?TOPIC_ID=9127
(I think you should post more codes like Page_Load and yourUpdateMethod)

--------------------------------------------
Mehdi.:)
 
Old April 8th, 2008, 07:38 AM
Authorized User
 
Join Date: Apr 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Chen,
I also have same problem?

Hello to everybody :
Do any one help us to get the actual work done..
Please do give us in step by step.







Similar Threads
Thread Thread Starter Forum Replies Last Post
How to store the dynamically generated controls ? ramesh1520 ASP.NET 2.0 Basics 0 January 2nd, 2008 10:30 PM
dynamically generated form SaraJaneQ Javascript How-To 4 November 9th, 2006 11:11 AM
dynamically generated submenus elladi Dreamweaver (all versions) 9 December 24th, 2004 08:12 AM
dynamically generated pop up menus... elladi Dreamweaver (all versions) 7 August 1st, 2004 03:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.