473,513 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with changing the index of the SelectedValue of a DropDownList

Hi everybody!

I have a dropdownlist on a aspx page. The dropdownlist is filled in the
page_load event like this:

If Not Page.IsPostBack Then
BindData()
End If

The Bind Data method goes to the database and reads the values for the
dropdownlist. In addition it selects the appropriate value:

ddlKind.SelectedValue = row.FK_KIND 'row.FK_KIND is from another table
ddl.DataBind()

This works fine!

Now I implemented the possibility for users to change information and save
it. This is where my problems occur after the user hits the "Save" button my
save event does the changes to the data. In the end i call the BindData()
method again to repopulate everything.
But this time the ddlKind does not get selected appropriate. It always
selects the first entry! Although in the debugger I can see that
ddlKind.SelectedValue is set to the correct value.

Any ideas what I might do wrong?

Thanks for help.
rgds,
tom
Nov 18 '05 #1
1 1264
I suspect your problem is that you are rebinding your dropdoanlist when you
don't need to.

Remember, the VIEWSTATE? This is going to store the current values in your
ddl (and the selected item) between calls to the page.

BUT if you rebind - you'll zap the viewstate and it will be repopulated with
the values from the db with nothing selected.

So: I reckon you need to ONLY bind your ddl on the very first Page_Load NOT
when you've saved the data too...

HTH

al*****@yahoo.com

"Thomas Kern" wrote:
Hi everybody!

I have a dropdownlist on a aspx page. The dropdownlist is filled in the
page_load event like this:

If Not Page.IsPostBack Then
BindData()
End If

The Bind Data method goes to the database and reads the values for the
dropdownlist. In addition it selects the appropriate value:

ddlKind.SelectedValue = row.FK_KIND 'row.FK_KIND is from another table
ddl.DataBind()

This works fine!

Now I implemented the possibility for users to change information and save
it. This is where my problems occur after the user hits the "Save" button my
save event does the changes to the data. In the end i call the BindData()
method again to repopulate everything.
But this time the ddlKind does not get selected appropriate. It always
selects the first entry! Although in the debugger I can see that
ddlKind.SelectedValue is set to the correct value.

Any ideas what I might do wrong?

Thanks for help.
rgds,
tom

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4552
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table...
2
4534
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
1
7407
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
2
1456
by: newsgroups.jd | last post by:
Thanks for any advice, help in advance... I have 3 dropdownlist that populate based on choice in the previous (nested essentially) Problem is when I hit the back button and make a change in...
11
5787
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
1663
by: | last post by:
I have a Datagrid and it has a dropdown. <asp:DropDownList DataSource="<%# PopulateList() %>" OnLoad="SelectIndex" > I assign selected index of the my dropdown in SelectIndex function....
0
2386
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
4
8536
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
2
6926
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.