473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DropDownList SelectedIndex stuck at -1 after IsPostBack

After selecting an option from the DropDownList and posting back, the
SelectedIndex for the DropDownList (ddlShippingMethods) remains at -1.
This form inherits from a base class. There is no code in the base
class that pertains to the dataset, ddl, datasource, etc. Any ideas
as to why this isn't working?

******Code******
Public Class frmPaymentOptions
Inherits clsMlknCsTestBase

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim dsShippingMethods As DataSet

dsShippingMethods = MyBase.prpCommerceObject.getShippingMethods

Me.ddlShippingMethods.DataTextField =
clsShippingMethodsConstants.cstrShippingMethodName

Me.ddlShippingMethods.DataValueField =
clsShippingMethodsConstants.cstrShippingMethodId

Me.ddlShippingMethods.DataSource = dsShippingMethods
If Not IsPostBack Then
Me.ddlShippingMethods.DataBind()
End If
Nov 17 '05 #1
1 1224
OK, figured it out.

I was working with a webform that contains child controls that were
created in the CreateChildControls() sub. The dropdownlist lost it's
index because the ViewState was looking here and on postback, was
lost. The answer to this problem is creating the child controls in
OnInit. Apparantly, when the bind is in OnInit, which occurs before
CreateChildControls(), the ViewState is left intact and the DDL index
remains. The code is as follows:

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
InitializePageControls()
End Sub

Sub InitializePageControls()
Try
Dim frmPageForm As HtmlForm 'form for page
Dim tblMaster As Table
Dim trowHeader As TableRow
Dim trowSubHeader As TableRow
Dim trowContent As TableRow

'All your code here.....

MyBase.CreateChildControls()

Catch err As Exception
Response.Write(err.ToString)
End Try
End Sub
cl*******@yahoo.com (Matthew) wrote in message news:<a0**************************@posting.google. com>...
After selecting an option from the DropDownList and posting back, the
SelectedIndex for the DropDownList (ddlShippingMethods) remains at -1.
This form inherits from a base class. There is no code in the base
class that pertains to the dataset, ddl, datasource, etc. Any ideas
as to why this isn't working?

******Code******
Public Class frmPaymentOptions
Inherits clsMlknCsTestBase

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim dsShippingMethods As DataSet

dsShippingMethods = MyBase.prpCommerceObject.getShippingMethods

Me.ddlShippingMethods.DataTextField =
clsShippingMethodsConstants.cstrShippingMethodName

Me.ddlShippingMethods.DataValueField =
clsShippingMethodsConstants.cstrShippingMethodId

Me.ddlShippingMethods.DataSource = dsShippingMethods
If Not IsPostBack Then
Me.ddlShippingMethods.DataBind()
End If

Nov 17 '05 #2

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

Similar topics

2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
0
by: Matthew | last post by:
After selecting an option from the DropDownList and posting back, the SelectedIndex for the DropDownList (ddlShippingMethods) remains at -1. This form inherits from a base class. There is no code...
5
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
3
by: Sam C | last post by:
Hi, I have an ASP.Net page which has a DropDownList on it. The DDL is populated via a method which is called from the Page_Load if IsPostBack = False. When the form is submitted the...
12
by: Frederik Vanderhaeghe | last post by:
Hi, I have a dropdownlist that contains should contain several values from the database, I fill it up in de page_load() with this code: If Not Page.IsPostBack Then InlezenConfig() Dim...
1
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: tasmontique | last post by:
I hope someone can help me. I have an error that I can not seem to figure out. All I need is an unbound dropdownlist to navigate to urls withing the website. I have gotten as far as to populate field...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.