|
-
Jun 24th, 2003, 08:25 AM
#1
Thread Starter
Frenzied Member
Page_load
I have this code, which works fine in my Page_load. But if I try to run the sub from SelectedIndexChanged then nothing happens. Do I have to specify something for my label like 'autopostback=true' for drpLists?
Code:
Protected Sub bindKappeDimension()
If Not Page.IsPostBack Then
Dim strCn As String = "Provider=Microsoft.jet.oledb.4.0;"
strCn += "Data Source=" & Server.MapPath("priser04.MDB") & ";"
Dim strSql As String = "Select Dim,Serie1 FROM SerieMat WHERE matId=" & intMatNr
Dim strResultsHolder As Integer
Dim objConnection As New OleDbConnection(strCn)
Dim objCommand As New OleDbCommand(strSql, objConnection)
Dim objDataReader As OleDbDataReader
objConnection.Open()
objDataReader = objCommand.ExecuteReader()
Dim medieDim As Integer
medieDim = CInt(Dim1.SelectedItem.Text)
Do While objDataReader.Read() = True
strResultsHolder = objDataReader("Dim")
kappe1.Text = strResultsHolder
Loop
objDataReader.Close()
objConnection.Close()
End If
End Sub
-
Jun 24th, 2003, 09:05 AM
#2
Because it causes a post back when SelectIndexChanged fires.
-
Jun 24th, 2003, 09:08 AM
#3
Hyperactive Member
I usually only use IsPostback within Page_Load so that certain code is only run the 1st time the form is loaded.
In your case, since the page has already been loaded at the time SelectedIndexChanged fires, the code inside the If Not IsPostback block will be bypassed.
Does this make sense?
-
Jun 24th, 2003, 02:03 PM
#4
Thread Starter
Frenzied Member
Hi, yes it does. Sorry, I just added the If Not IS.... when I tried to troubleshoot the sub. If I delete this nothing still happens. It has something to do with the Do While I think.
-
Jun 24th, 2003, 02:28 PM
#5
Hyperactive Member
Well do you know for sure that the sub is called by SelectedIndexChanged? If you're not using Vis Studio and cannot debug try using response.write().
You only need the AutoPostBack="True" if you want to post as soon as a new list item is selected.
Also as you suggest it could well be that no rows are returned for the new query. It all depends on what intMatNr is...
-
Jun 25th, 2003, 03:40 AM
#6
Thread Starter
Frenzied Member
It worked when I use a Do While Loop and used Exit Do at the right place. But you were right, I've forgot to set the intMatNr. Thanks
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
|