View Full Version : ASP.NET 2.0 Gridview Popup

02-12-2007, 05:42 PM
Here is what I want to accomplish. Currently I have a gridview that I am using to populate data from my SQL Server 2000 DB. The client presses edit which puts the grid into edit mode. They make a change to the dropdownlist in the row and then press Update. Prior to updating I want to check the database to make sure that the value they are selecting has not already been assigned in the database. If it has been assigned I want to show a popup stating that the item they have selected in the dropdown has already been assigned and would they like to continue. If they say yes that they would still like to update then I will assign the value in the database and unassign the previous record putting in its place a null value. Here is the code I am currently using to do this. The problem is that I am using a msgbox function that can only be used on my machine becuase I am running, I assume, in a protected enviromnment that lets me have access to the PC I am coding on from IIS. Hopefully this all makes sense.

'New Printer value
Dim sNewPrinter As String = e.NewValues.Item(0)
'Check to see if printer exists already
e.NewValues.Item(2) = Session("SAPID")
Dim SID As String = e.NewValues.Item(2)

Dim sReturn As String = retAnswer(sNewPrinter)
Dim sArray() As String = sReturn.ToString().Split("|")
Dim j As Integer = 0
Dim sAnswer As String = ""
Dim sExistStat As String = ""
sAnswer = sArray(0).ToString()
sExistStat = sArray(1).ToString()

If sAnswer = "YES" Then
If MsgBox("Printer " & sNewPrinter.ToString() & " already exists on " & sExistStat.ToString() & ". Do you still want to update?", MsgBoxStyle.YesNo, "Test Title") = MsgBoxResult.No Then
e.Cancel = True
MsgBox("Item was not updated.", MsgBoxStyle.OkOnly, "Item not updated")
End If
End If


02-12-2007, 07:59 PM
MessageBox is Windows Forms.
Is this a windows forms app, or a web forms app?
If web forms, you'll have to register a client side script block to accomplish this and use javascript alert.

02-14-2007, 10:41 PM
Thanks for your reply. This a web app. It does work through VS 2005 but only because it runs the application through the development server which has access to the "desktop". It is new for VS 2005 I believe. I have attempted to work on it through a javascript call from the code-behind but as you can imagine it still attempts to run the server side script.

02-15-2007, 03:21 PM
Yeah, this architecture won't work on a web app.
You'll have to use javascript if you want an actual alert. Either register script block or the new onClientClick.

I prefer to just use a confirmation "page" (just a placeholder control set visible or not) and take the hit of the postback, especially for things where a user might not have javascript enabled and I get a postback anyway, such as gridView updating.