Results 1 to 6 of 6

Thread: [2005] Couple of newbie problems ....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    [2005] Couple of newbie problems ....

    Hello all,
    I've prepared a page that has a couple of DropDownLists.
    When the value of DropDownList1 is changed, it prepares a list of items in DropDownList2 based on the value of DropDownList1.
    The data for the lists comes from an Excel spreadsheet which is captured as soon as the form is loaded.
    Unfortunately, I can only get the correct values into DropDownList2 if the AutoPostBack property of DropDownList1 is true. However, what I'm finding is that by setting AutoPostBack to true, it loads the data again when the value of List1 is changed.
    I've tried setting a boolean flag to indicate that the data is loaded, and check for it before loading the data, but this is reset because of the AutoPostBack (I think).
    Any pointers would be appreciated.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: [2005] Couple of newbie problems ....

    I assume that you load the excel sheet in the Page_Load. You can do the following. Your excel sheet should not get loaded for the post back.

    VB Code:
    1. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2.     If Not Page.IsPostBack Then
    3.            <do your excel thing>
    4.     End If
    5. End Sub
    Last edited by space_monkey; Dec 13th, 2007 at 10:23 AM.
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Couple of newbie problems ....

    Thanks for your reply.
    Unfortuantely, what I'm finding now is that the Excel data NEEDS to be loaded again when DropDownList1 is changed so that it can populate DropDownList2. Without loading it again, the DataTable simply doesn't exist to allow me to extract the data from it to fill DropDownList2.
    Why is it forgetting about the DataTable?
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Couple of newbie problems ....

    Show your code. The code you're using to make calls and populate the dropdownlist.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Couple of newbie problems ....

    I changed my source data from Excel, to XML - mainly because Excel seems to be very difficult process to clear (but that's another subject!).
    It still loads the data whenever a DropDownList is changed, but it seems quicker, and is less of a problem.
    However, the main bits of code are:

    Code:
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            FillDataSet()
    
        End Sub
    
        Private Sub FillDataSet()
    
            ' The DataSet details
            dsDataSet = New DataSet("ErrorCodes")
            dsDataSet.ReadXml(strErrors)
    
        End Sub
    
        Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    
            ResetProblemAndSolution(False)
            Me.DropDownList2.Enabled = True
            FillModulesDropDownList()
    
        End Sub
    
        Private Sub FillModulesDropDownList()
    
            Me.DropDownList2.Items.Clear()
            Me.DropDownList2.Items.Add("[select from list]")
    
            ... just some stuff to fill DropDownList2 ... nothing special!
    
        End Sub
    
        Private Sub ResetProblemAndSolution(ByVal blnTrueOrFalse As Boolean)
    
            ... makes some labels visible/invisible
    
        End Sub
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Couple of newbie problems ....

    Have you tried Page.IsPostBack with the new code? Or is your code working now?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width