Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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 August 11th, 2010, 03:17 AM
Authorized User
 
Join Date: Jun 2010
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default ListView list controls display wrong data the 3rd time

I have a ListView that populates and displays a user's data (via a profile system in VWD 2008) during Page_Load and also when I go from the EditItemTemplate to the ItemTemplate. Then when I go to the edit screen again, my DropDownList and RadioButtonList controls display the first items in the corresponding tables instead of the correct profile values. I don't understand why the controls populate correctly the first and second times but not on the third time (that's right, the third time is NOT a charm); I hope someone can help me understand how to solve this problem.

ItemTemplate:
Code:
 <asp:DropDownList ID="ddlTState" AppendDataBoundItems="True" DataSourceID="srcState"  
     DataTextField="StateName" DataValueField="StateName" Enabled="False" TabIndex="125"  
     runat="server" />  

      <asp:DropDownList ID="ddlTState" AppendDataBoundItems="True" DataSourceID="srcState"
          DataTextField="StateName" DataValueField="StateName" Enabled="False" TabIndex="125"
          runat="server" />
EditItemTemplate:
Code:
 <asp:DropDownList ID="ddlEState" AppendDataBoundItems="true" DataSourceID="srcState"  
     DataTextField="StateName" DataValueField="StateName" TabIndex="125" runat="server">  
     <asp:ListItem Text="--State--" Value="" />  

      <asp:DropDownList ID="ddlEState" AppendDataBoundItems="true" DataSourceID="srcState"
          DataTextField="StateName" DataValueField="StateName" TabIndex="125" runat="server">
          <asp:ListItem Text="--State--" Value="" />
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load  
     lsv = Util.FindChild(Me, "lsvProfile")  'Util.FindChild instead of FindControl
     'If Not IsPostBack Then  
     ddl = Util.FindChild(lsv, "ddlEState")  
     If ddl IsNot Nothing Then ddl.SelectedValue = Profile.State  
     ddl = Util.FindChild(lsv, "ddlTState")  
     If ddl IsNot Nothing Then ddl.SelectedValue = Profile.State  
     'End If  
 End Sub
 
Old August 12th, 2010, 06:49 PM
Authorized User
 
Join Date: Jun 2010
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Resolved with this code:

Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        lsv = Util.FindChild(Page, "lsvProfile")
        If Not IsPostBack Then
            Try
                lsv.EditIndex = 0
                rbl = Util.FindChild(lsv, "rblEGender")
                If rbl IsNot Nothing Then rbl.SelectedValue = Profile.Gender
                ddl = Util.FindChild(lsv, "ddlEState")
                If ddl IsNot Nothing Then ddl.SelectedValue = Profile.State
                ddl = Util.FindChild(lsv, "ddlEBirthDay")
                If ddl IsNot Nothing Then ddl.SelectedValue = Profile.BirthDay
                ddl = Util.FindChild(lsv, "ddlEBirthMo")
                If ddl IsNot Nothing Then ddl.SelectedValue = Profile.BirthMo
            Catch ex As Exception
            End Try
        End If
    End Sub

    Protected Sub lsvProfile_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles lsvProfile.ItemDataBound
        ddl = Util.FindChild(Me, "ddlEState")
        If ddl IsNot Nothing Then ddl.SelectedValue = Profile.State
        ddl = Util.FindChild(Me, "ddlEBirthMo")
        If ddl IsNot Nothing Then ddl.SelectedValue = Profile.BirthMo
        ddl = Util.FindChild(Me, "ddlEBirthDay")
        If ddl IsNot Nothing Then ddl.SelectedValue = Profile.BirthDay
        rbl = Util.FindChild(Me, "rblEGender")
        If rbl IsNot Nothing Then rbl.SelectedValue = Profile.Gender

    End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding data display in windows controls akssmv ADO.NET 4 May 8th, 2009 09:19 AM
Data Bind ComboBox to display the List Bjay Pro VB Databases 0 July 29th, 2007 02:57 PM
Unable to display data using drop down list hayley Classic ASP Databases 2 January 18th, 2005 05:36 AM
Data Binding to List Controls dejawoo ASP.NET 1.0 and 1.1 Professional 2 July 3rd, 2004 10:54 PM
Visible property of controls in data list acko ASP.NET 1.x and 2.0 Application Design 1 December 9th, 2003 10:41 AM





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