|
-
Dec 13th, 2007, 05:10 AM
#1
Thread Starter
Addicted Member
[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.
-
Dec 13th, 2007, 10:19 AM
#2
Fanatic Member
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:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
<do your excel thing>
End If
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
-
Dec 14th, 2007, 09:09 AM
#3
Thread Starter
Addicted Member
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?
-
Dec 17th, 2007, 02:46 PM
#4
Re: [2005] Couple of newbie problems ....
Show your code. The code you're using to make calls and populate the dropdownlist.
-
Dec 18th, 2007, 04:05 AM
#5
Thread Starter
Addicted Member
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
-
Dec 18th, 2007, 08:31 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|