Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > ASP.net 2.0 Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2006, 10:01 AM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default ASP.net 2.0 Problem


I am probably missing something incredibly obvious, but I've compared this code to something else I wrote that does the exact same thing and don't see any reason why one works and one doesn't. (Maybe I just need more coffee)

I've got a form with 2 list boxes, one box has all of the modules required by a user, the other box has every other module. Pretty simple. There's 2 buttons to move selected items between the boxes which is where I run in to issues. Nothing throws an error but nothing happens when the buttons are pressed, the page posts back but the modules are never moved between the boxes.

One button calls AddRem with "Add" the other with "Rem"

Code:
Private Sub AddRem(ByVal action As String) Dim cmdUpdate As OleDbCommand Dim strSQL As String If action = "Add" Then Try If Conn.State = ConnectionState.Closed Then Conn.Open() For Each li As ListItem In lstNotReqd.Items If li.Selected Then strSQL = "Insert INTO trainingrecords (employee, moduleid, firstroundrequired) Values (" & Request.QueryString("empID") & ", " & li.Value & ", true)" cmdUpdate = New OleDbCommand(strSQL, Conn) cmdUpdate.ExecuteNonQuery() End If Next Catch ex As Exception txtEmpName.Text = ex.ToString Finally Conn.Close() End Try Else Try If Conn.State = ConnectionState.Closed Then Conn.Open() For Each li As ListItem In lstReqd.Items If li.Selected Then strSQL = "Delete from trainingrecords where employee = " & Request.QueryString("EmpID") & " and moduleid = " & li.Value _ & " and createdbydept <> 2" cmdUpdate = New OleDbCommand(strSQL, Conn) cmdUpdate.ExecuteNonQuery() End If Next Catch ex As Exception txtEmpName.Text = ex.ToString Finally Conn.Close() End Try End If GetRecs() End Sub

Like I said the try catch blocks there never actually throw an error which is what's confusing me, and the values are never inserted into the database. The reason records cannot be deleted if createdbydept = 2 is because those are mandatory modules created by HR, HR has a seperate admin program they can use to add/remove those records, this one is for general purpose users.

The list boxes are populated through this sub:
Code:
Private Sub GetRecs() Dim rdr As OleDbDataReader Dim li As New ListItem Dim cmd As New OleDbCommand("select Modules.ModuleName, TrainingRecords.FirstRoundRequired, " _ & " Modules.Moduleid FROM TrainingRecords inner JOIN Modules ON TrainingRecords.ModuleID = Modules.ModuleID WHERE " _ & " TrainingRecords.Employee = " & Request.QueryString("EmpID") & " order by modules.modulename", Conn) Try If Conn.State = ConnectionState.Closed Then Conn.Open() rdr = cmd.ExecuteReader lstReqd.DataSource = rdr lstReqd.DataTextField = "modulename" lstReqd.DataValueField = "moduleid" lstReqd.DataBind() rdr.Close() cmd.CommandText = "Select modulename, moduleid from modules where moduleid not in (select moduleid " _ & " FROM TrainingRecords WHERE Employee = " _ & Request.QueryString("EmpID") & ") order by modulename" rdr = cmd.ExecuteReader lstNotReqd.DataSource = rdr lstNotReqd.DataTextField = "modulename" lstNotReqd.DataValueField = "moduleid" lstNotReqd.DataBind() Catch ex As Exception txtEmpName.Text = ex.ToString End Try End Sub

Like I said this is probably something glaringly obvious that I've just overlooked and can't find, but any input would be appreciated.

Edit:
It actually looks like the li items in AddRem aren't retaining their selected state when they're created.. hmm

Last edited by Nayru; 07-18-2006 at 10:14 AM.
Reply With Quote
  #2  
Old 07-18-2006, 08:15 PM
obajaber's Avatar
obajaber obajaber is offline
Centurion
 
Join Date: Feb 2005
Posts: 118
Default

what's in your page load?
Reply With Quote
  #3  
Old 07-19-2006, 07:10 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

It sounds like you are rebinding your grid before you run the code to do the updates. That would cause it to "forget" what you asked for. Make sure you only rebind your grids after you handle their post back events.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #4  
Old 07-19-2006, 01:31 PM
Nayru's Avatar
Nayru Nayru is offline
Centurion
 
Join Date: May 2006
Location: GTA
Posts: 119
Default

Thanks for the input, I ended up having to scrap the listboxes because it was too complicated for HR.

Now it's just a big ugly list of 50+ check boxes

But your suggestion of it rebinding was probably correct, I think in testing I took out the test for post back so it probably was reloading the grid, I just completely missed it.

Thanks again
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->