|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DropDownList resets selectedIndex on postbackI have a dropdownlist (ddL). When I run the app and I try to select an item it alsways get selected the first item. I fill the ddl on pageload with: "if not ispostback" statement. Function that fills the ddl: For i = 0 To alAsigs.Count - 1 Dim c As New ListItem c.Text = alAsigs(i).NombreAsignatura & " (" & alAsigs(i).Curso & alAsigs(i).Grupo & ")" c.Value = alAsigs(i).IdEsAsignatura ddlAsignaturasExam.Items.Add(c) End If Next This is going me crazy as it's the first time I get this problem (I just changed from .NET 1.1 to NET 2.0). Any help? Thanks Juan Puebla One thing I would check is to make sure that the EnableViewState=True for
the DropDownList. Also, make sure that you do not have EnableViewState=False in your .aspx's @Page directive. Also, I would like to ask why do you have your End If line before your Next line? Take a look at these things, if you still have the problem try posting the complete code for people to see, sometimes there are things we don't think of the first time around. Show quoteHide quote "Juan Puebla" <JuanPue***@discussions.microsoft.com> wrote in message news:CF6859DE-8F68-472E-BB50-2EF57DFABCC0@microsoft.com... > Hi, > > I have a dropdownlist (ddL). When I run the app and I try to select an > item > it alsways get selected the first item. I fill the ddl on pageload with: > "if > not ispostback" statement. Function that fills the ddl: > > For i = 0 To alAsigs.Count - 1 > Dim c As New ListItem > c.Text = alAsigs(i).NombreAsignatura & " (" & > alAsigs(i).Curso & alAsigs(i).Grupo & ")" > c.Value = alAsigs(i).IdEsAsignatura > ddlAsignaturasExam.Items.Add(c) > End If > Next > > > This is going me crazy as it's the first time I get this problem (I just > changed from .NET 1.1 to NET 2.0). > > Any help? > > > Thanks > > Juan Puebla Thanks for your answer. There was a line missing to start If statement. As
you see, I've changed the "value" of each listitem. Now I also use the variable "i" with a coma. I don't know why but with this it works. When I need the value I use a substring(indexof(",") + 1). I don't really understand why.... Dim i As Int16 For i = 0 To alAsigs.Count - 1 If alAsigs(i).Trimestre = ddlTrimExam.SelectedItem.Text Or alAsigs(i).Trimestre = 0 Then Dim c As New ListItem c.Text = alAsigs(i).NombreAsignatura & " (" & alAsigs(i).Curso & alAsigs(i).Grupo & ")" c.Value = i & "," & alAsigs(i).IdEsAsignatura ddlAsignaturasExam.Items.Add(c) End If Next Show quoteHide quote "Nathan Sokalski" wrote: > One thing I would check is to make sure that the EnableViewState=True for > the DropDownList. Also, make sure that you do not have EnableViewState=False > in your .aspx's @Page directive. Also, I would like to ask why do you have > your End If line before your Next line? Take a look at these things, > if you still have the problem try posting the complete code for people to > see, sometimes there are things we don't think of the first time around. > -- > Nathan Sokalski > njsokal***@hotmail.com > http://www.nathansokalski.com/ > > "Juan Puebla" <JuanPue***@discussions.microsoft.com> wrote in message > news:CF6859DE-8F68-472E-BB50-2EF57DFABCC0@microsoft.com... > > Hi, > > > > I have a dropdownlist (ddL). When I run the app and I try to select an > > item > > it alsways get selected the first item. I fill the ddl on pageload with: > > "if > > not ispostback" statement. Function that fills the ddl: > > > > For i = 0 To alAsigs.Count - 1 > > Dim c As New ListItem > > c.Text = alAsigs(i).NombreAsignatura & " (" & > > alAsigs(i).Curso & alAsigs(i).Grupo & ")" > > c.Value = alAsigs(i).IdEsAsignatura > > ddlAsignaturasExam.Items.Add(c) > > End If > > Next > > > > > > This is going me crazy as it's the first time I get this problem (I just > > changed from .NET 1.1 to NET 2.0). > > > > Any help? > > > > > > Thanks > > > > Juan Puebla > > >
Master Detail Event Handling?
Date masked textbox for user input ASP.NET 2.0 Databind during Client Callback How to turn off padding within a Web Part? Problem with FindControl Hide show asp table need help in web user control Strange behavior with gridview and selectedindex Absolute Positioning in Web User Controls CheckboxList problem |
|||||||||||||||||||||||