Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2011, 01:11 AM
Authorized User
 
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
Default Need to be able to limit update fields on page

This might be to difficult to explain but I'm going to give it a try. I have a page to update some server information.
I'm trying to use the same code in order to avoid rebuilding a page from scratch. In my update, I only want one field to be able to be changed. We have a table called "Dropdownlist" that holds our options. During the update phase, the field is populated with the option we have listed in the table. We use these options to update another table.
If I choose a select * in my query, the page works fine but displays all fields, I only want to show two fields and give the option to change the server owner.

Code:
Code:
<%@ Language=VBScript%>
<% Option Explicit %>
<% Response.Buffer = True %>
<!-- #include file = "conn.asp" -->
<html>
	<title>Update Server Owner</title>
	<head>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
	</head>
<%
Dim strComputer
strComputer = Request.QueryString("servername")
%>
	<!--<meta http-equiv=refresh content='60; url=index.asp'>-->
	<body bgcolor="WhiteSmoke">
		<style type="text/css">
    TD.content { BACKGROUND-COLOR: #ffffff }
    .clsBodyText { FONT-WEIGHT: normal; FONT-SIZE: 8pt; FONT-FAMILY: Verdana; font-style: normal  }  
    .clsFieldLabel {FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana; }  
    .clsLabelHeading{FONT-WEIGHT: bold;FONT-SIZE: 12pt;COLOR: black; FONT-FAMILY: Verdana;} 
    .linkroll { font-family:Arial; font-size:8pt; font-style:normal; font-weight:bold; letter-spacing:normal; 
                text-decoration:none; text-transform:none; color:#858BFD; }  
                A.linkroll:hover { font-weight:bold;    color:black }</style>
	
		<%
Dim intPass
intPass = Request("PASS") 
' -- Take Action based on how you came into this page
Select Case Trim(intPass)
	Case Trim("1")
		' -- Repeat Visit, update the data
		UpdateData
	Case Else
		' -- First Time Visit, display HTML Form
		DisplayHTMLForm
End Select

' -- Make sure nothing else gets processed
Response.End
Sub DisplayHTMLForm()

Dim conn2, conn3, objConn2 , objConn3, objRS2, i, f, cfval, k, j
Dim objRS3

Set conn2 = Server.CreateObject("ADODB.Connection")
Set conn3 = Server.CreateObject("ADODB.Connection")
conn2.ConnectionString = sConnection2
conn3.ConnectionString = sConnection2
conn2.Open
conn3.Open
Set objRS2 = conn2.Execute("SELECT * FROM serverreview WHERE SERVER_NAME='" & strComputer &"'") 
%>
*****I would like to change the "*" to server_name, server_owner********
<FORM ACTION="serverupdateowner.asp?servername=<%=strComputer%>" METHOD="POST"> 
<INPUT TYPE="hidden" NAME="PASS" VALUE="1">
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="2" WIDTH="100%" align="left">	
	<tr>
				<td colspan="2" align="center" class="clsFieldLabel">
				Update Record for <%=strComputer%><br><a class=clsBodyText>Change the Server Owner.</a></tr>
	
<%

   objRS2.MoveFirst
   ' -- Output data
   For i = 0 to objRS2.Fields.Count - 1
      Response.write "<TR>" 
      Response.Write "<TH align='left' width='30'><a class=clsBodyText align='left'>" & objRS2.Fields(i).Name
      ' - output value as a textbox, except for ID field
cfval = objRS2.Fields(i)
      If objRS2.Fields(i).Name = "SERVER_NAME" OR _ 		 
		 objRS2.Fields(i).Name = "Server_UPDATE" Then

         ' - output a text box
            Response.Write "</a></TH><TD><INPUT TYPE=""TEXT"" " & _ 
            " NAME=""" & _ 
            objRS2.Fields(i).Name & _ 
            """ VALUE=""" & objRS2.Fields(i) & _ 
            """ SIZE=""60"" readonly class=clsBodyText style=background-color:#eeeeee ></TD>" 
         ElseIf  objRS2.Fields(i).Name = "Status" OR _  
 objRS2.Fields(i).Name = "Server_Owner" OR _  
 objRS2.Fields(i).Name = "Virtual_Machine" Then
Set objRS3 = conn3.Execute("SELECT * FROM DropDownList WHERE STable='serverreview' AND SColumn='" & objRS2.Fields(i).Name & "'") 
k = 0
Response.Write "*</a></TH align='left'><TD><select class=clsBodyText NAME=" & objRS2.Fields(i).Name & " >"
For j = 2 to objRS3.Fields.Count - 1

If LCase(objRS3.Fields(j)) = LCase(cfval) Then
Response.Write "<option selected=""selected"" VALUE='" & objRS3.Fields(j) & "' >" & objRS3.Fields(j) & "</option>"
k = 1
Else 
If objRS3.Fields(j) <> "" Then
Response.Write "<option VALUE='" & objRS3.Fields(j) & "' >" & objRS3.Fields(j) & "</option>"
End If
End If
Next
If k = 0 Then
Response.Write "<option size=""40"" selected=""selected"" value="""">Please Select...</option>"
End If

Response.Write "</select></TD>"
objRS3.Close
Set ObjRS3 = Nothing


Else 

         ' - output a text box
            Response.Write "*</a><TD><INPUT TYPE=""TEXT"" " & _ 
            " NAME=""" & _ 
            objRS2.Fields(i).Name & _ 
            """ VALUE=""" & objRS2.Fields(i) & _ 
            """ SIZE=""60"" class=clsBodyText></TD>" 
End If 
      Response.write "</TR>" 
   Next
objRS2.Close
Set objRS2 = Nothing
conn2.Close
Set conn2 = Nothing
%>
<TR><TD> </TD><TD><INPUT TYPE="SUBMIT" VALUE="  Update  "></TD></TR>
</TABLE>
</FORM>
<%End Sub
Sub UpdateData()


Dim conn3, objConn3 , objRS3, objRS4, i
Set conn3 = Server.CreateObject("ADODB.Connection")
conn3.ConnectionString = sConnection2


dim Field(85)
conn3.Open
Set objRS3 = conn3.Execute("SELECT * FROM serverreview WHERE SERVER_NAME='" & strComputer &"'") 
objRS4 = "UPDATE serverreview SET "
For i = 0 to objRS3.Fields.Count - 1
Field(i) = Request("" & objRS3.Fields(i).Name & "")
objRS4 = objRS4 + objRS3.Fields(i).Name + "='" + Field(i) +"'"
If i <> objRS3.Fields.Count - 1 Then
objRS4 = objRS4 + ","
end if

 Next
objRS4 = objRS4 + " WHERE SERVER_NAME='" & strComputer & "'"

conn3.Execute(objRS4)
if err<>0 then
    response.write("Record Not Updated")
  else
    response.write("" & strComputer & " was updated!")
  end if
End Sub
objRS3.Close
Set objRS3 = Nothing
objConn4.Close
Set objConn4 = Nothing
objRS4.Close
Set objRS4 = Nothing
%>

	</body>
</html>
Please let me know if more information is needed or if there just might be an easier way. Still trying to learn the basics of ASP, but I'm starting to get the hang of it.

Thanks.
 
Old October 19th, 2011, 01:01 PM
Authorized User
 
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
Default

So I did not figure out the right resolve but I did find a way to grey out the fields.

in the code, there is a section:
Code:
cfval = objRS2.Fields(i)
      If objRS2.Fields(i).Name = "SERVER_NAME" OR _
If you keep adding your Fields(i).Name = "Column_Name" OR _, those will be greyed out and will not be able to be edited.

Hope this helps someone who needs an update page.
 
Old October 19th, 2011, 05:45 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

A tip for you. Just post the problematic code in future. Simply posting the entire page will put most people off helping you. Help others help you...

So based on that you should have figured I have not looked throught your 100+ lines of code. Anyhow...

;;;I'm trying to use the same code in order to avoid rebuilding a page from scratch
If you mean you want to use the same page for updating different scenarios, yes very good this is best.

I find your explanation a bit odd, I assume you either want to:

1..Show a number of form elements on a page but only allow 2 of then to be updatable?
if so you should use the 'read only' or the 'disabled' properties of the <input type ...> or <select ...> elements.

2..And or upate ony 2 of a number of fields in your update statement. I tend to conditionaly detect and update where required. EG this query looks for a value in the form element called roleID and only updates the field if a value has been found.
Code:
 
sql = "UPDATE users SET aTitle='" & trim(request.form("tTitle")) & "', fName='" & trim(request.form("tFirstName")) &  "'"
if request.form("role") <> "" then
   sql = sql & ",roleID=" & trim(request.form("role")) & ""
end if
sql = sql & " WHERE ID=" & trim(request.form("theID")) & ";"
Hope that helps
__________________
Wind is your friend
Matt
 
Old October 19th, 2011, 06:48 PM
Authorized User
 
Join Date: Aug 2011
Posts: 34
Thanks: 1
Thanked 1 Time in 1 Post
Default

Looks good. I appreciate your suggestion for future postings.

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Page Limit (no of lines per page) snufse Crystal Reports 1 May 26th, 2008 08:02 AM
Add a Dropdownlist to update fields on a page cesemj ASP.NET 2.0 Basics 1 October 4th, 2007 11:24 AM
update a fields value Vince_421 Access VBA 2 May 19th, 2006 06:41 AM
Limit access to upload page functionality jacob ASP.NET 1.0 and 1.1 Professional 2 November 23rd, 2005 03:02 PM
Group Page Limit glewis1636 BOOK: Professional Crystal Reports for VS.NET 0 February 15th, 2005 04:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.