I am trying to disable the default value for an asp select list, the default value being the string "null".
I want this to remain as the default, but when the user has selected another item in the select list to disable it as a selectable option.
The ASP code for the select list is below:
Response.Write "<Select name=""PersonID" & temporary.Fields("EventID") & class=""SelectText"" style=""width:100%"">" & vbCrLf &_
"<Option value=""NULL""></Option>"
Not sure why you would need to do this, usually you convert the empty value to null in your backend script if needed, or you can use something like jQuery to do this client-side, hoping that your browser has javascript enabled:
$("select").change(function(e){
$("option[value='NULL']:first",this).remove();
});
This will remove the first null option in your select list on change. If you need more help with javascript/jquery, you should tag your questions as so.
Alternatively to Zee Tee's answer, you could read the value on post back and determine its value...
<select id="personId" name="personId<%=eventId%>" class="selectText">
<option value="-1">-- Please select a value --</option>
<option value="1">......</option>
</select>
...and the postback code...
Dim personId, failForm
personId = Request.Form("PersonId")
failForm = (personId = -1)
Related
Apologies about the language, I'm maintaining a legacy system which is all in ASP Classic.
I have a html page which has content generated from my SQL Server via ASP
<form method="POST">
<div class="container">
<table id="table" class="table">
<thead class="thead-dark">
<tr>
<th scope="col" data-field="article">Article</th>
<th scope="col" data-field="item">QTY/th>
I then generated the content with a while loop from my dB which displays the content correctly :
<%
While not grs.eof
%>
<tr>
<!--SQL query from ASP-classic-->
<th><%=grs.fields("Article")%></th>
<input type="number" class="form-control" id="Quant" placeholder="<%=grs.fields("QTY")%>" name="qty"></th>
<%
grs.movenext
wend
%>
</tr>
</table>
</form>
Now, above my table I have a button
<button type="submit" value="Submit" class="btn btn-primary mb-2" name="B1">Confirm</button>
When my end user clicks submit, I want all the values to be updated into my SQL server, now as this is within a for loop I wasn't sure where the Update query would go.. I have this so far
<%
If request.form("B1")="Submit" Then
If QTY = "" Then
QTY = 0
Else
QTY = request.form("QTY")
'Update SQL'
gsSQL2 = "UPDATE dB SET quant ='" & QTY & "' WHERE ID = '" & request.querystring("ID") & "' And Article = '" & grs.fields("Article") &"'"
gobjConn.Execute(gsSQL2)
(please note my code is indented properly in my IDE)
Now, when I click submit within the While loop I get the ID number seperated by a comma, so I know it's updating but I'm really unsure as to what I'm doing wrong..?
any help would be much appreciated.
if any further information is needed let me know.
Expected output is to display some Article Codes codes on a website and take a response from the user, then write that output to my SQL dB where the Article = Article and ID = ID.
main query to generated content (this doesn't match my sample data but I'll post incase the mistake is in the query itself)
gsSQL = "SELECT ID, Article, [Item Name] as name, [Stock Quantity] as qty, Built, Boxed, Actual from dB where Store ='" & request.querystring("store") & "' order by [Category], name "
Set grs = gobjConn.Execute(gsSQL)
With hopes that I understand you correctly, you have id, quant, and article already in database and want to update the quant related to the ID. In that case:
In the loop that creates the form give each number input a name with the ID in the name (or if you just have one field just have the ID as the name). In your case:
<input type="number" name="qty<%=rs("ID")%>">
On the action page you then loop through all the fields and update accordingly, either you do a replace on the name to get the ID, or if you only use the ID as fieldname it works without replace:
For Each Item In Request.Form
fieldName = Item 'This is the ID (with above field name: qtyID where ID is the ID from the DB.
fieldValue = Request.Form(Item) 'This is the Quantity of that Article ID
articleid=replace(fieldName,"qty","")
sql="update table set qty=" + fieldValue + " where id=" + articleid
Next
That way you will go through all the fields in the form. I am also unsure if you need both ID and Article in where clause? Can one ID have many Articles or vice versa?
I need to pass a server-side parameter to my SqlDataSource SELECT IN-clause as follows (notice the parameter #InClause and it's location in the SQL-select that is defined in the aspx (for the SqlDataSource):
SELECT UID_REPORT, TXT_RPT_TEXT, TXT_RPT_NAME, TXT_RPT_ASPX_PAGE, TXT_RPT_TYPE
FROM REPORTS WHERE (UID_REPORT IN (#InClause))
ORDER BY INT_SORT_ORDER
But this does not pass validation in the Test-Query operation.
The '#InClause' parameter gets it's value from a HiddenField control.
I want to set this value based on some conditions. for example If DIVISION=5 then #InClause would ="45,46" Else ="14,15".
Any suggestions on how to pass the IN ( ... ) values by the hiddenfield.Value (which is a string, of course).
Thanks.
You need split string function to do this
SELECT uid_report,
txt_rpt_text,
txt_rpt_name,
txt_rpt_aspx_page,
txt_rpt_type
FROM reports
WHERE uid_report IN (SELECT split_value
FROM Udf_splitstring(#InClause, ','))
ORDER BY int_sort_order
Check the below links to create a split string function
http://sqlperformance.com/2012/07/t-sql-queries/split-strings
http://www.sqlservercentral.com/articles/Tally+Table/72993/
or of-course you can use dynamic sql
I have a listbox in VB.NET that allows users to select multiple categories. I need to put these categories into a database and need the index value from the listbox of the categories as the database works off IDs. SelectedItems (with an s) does not work in the net application.
I have tried the following code:
For Each category As ListItem In CategoryListBox.Items
If category.Selected Then
Dim courseCategory As New CourseCategory
courseCategory.CourseID = course.ID
courseCategory.CategoryID = CategoryListBox.SelectedIndex
Using courseCategoryEntities As New Eng_NWDTrainingWebsiteEntities
courseCategoryEntities.CourseCategories.Add(courseCategory)
courseCategoryEntities.SaveChanges()
End Using
End If
Next
When iterating through the loop the code that is:
courseCategory.CategoryID = CategoryListBox.SelectedIndex
works correctly the first time around.
On the second iteration of the loop, it goes to the next selected item however returns the index for the first selected value. How do I return the values of the other indexes selected?
It depends on what ID you need to pass to your database. If it is truly the index of the ListItem in the ListBox, then you would use:
courseCategory.CategoryID = CategoryListBox.Items.IndexOf(category);
That may not be the best approach however. Maybe the order of the ListItems changes, messing up your indexes. You probably want to store the actual CategoryID on each ListItem. The Value property works well for that. You set the column you want as the DataValueField like so:
<asp:ListBox ID="CategoryListBox" runat="server"
DataValueField="CategoryID "></asp:ListBox>
So as you are looping through each ListItem in the ListBox and checking if it is selected, just use it's Value property.
For Each category As ListItem In CategoryListBox.Items
If category.Selected Then
Dim courseCategory As New CourseCategory
courseCategory.CourseID = course.ID
courseCategory.CategoryID = category.Value;
Using courseCategoryEntities As New Eng_NWDTrainingWebsiteEntities
courseCategoryEntities.CourseCategories.Add(courseCategory)
courseCategoryEntities.SaveChanges()
End Using
End If
Next
Fixed the code by deselecting the item in the listbox after it was successfully saved.
End Using
category.Selected = False
End If
This solved my problem.
i have an input field whose value is coming from a variable, when i submit the form record insert as an empty row :(
if i check the view-source of my page it clearly prints the value but does not insert it.
Here is the Input Field:
<input name="uid" type="text" value="<%Response.Write(studentid)%>" disabled="disabled" />
Here is the Insert Code:
<%
if request.Form("MyRecord")="Insert" then
Set InsCom=Server.CreateObject("ADODB.Command")
InsCom.ActiveConnection=objConn
InsF = Trim(request.Form("uid"))
InsF = replace(InsF,"'","''")
InsCom.CommandText = "Insert into talent_hunt(uid)Values(?) "
InsCom.Parameters.Append InsCom.CreateParameter("#uid", adVarChar, adParamInput, 255, InsF)
InsCom.Execute
response.Write"Record Inserted Successfully!<br /><a href=""talent-hunt.asp"" />Go Back to main page</a>"
end if
%>
Please help...
Use readOnly instead of disabled.
ref. thread: How can I get the form value from a disabled <input> element
Current select statement:
SELECT *
FROM vw_svc200_open
WHERE (CUSTNMBR = '::CUSTNMBR::')
ORDER BY ::sortcolumn::
This works and all is well. But now I need to modify this select string to apply an extra filter.
SELECT *
FROM vw_svc200_open
WHERE
CASE
WHEN ::CUSTNMBR:: = 'ABC123'
THEN (CUSTNMBR = '::CUSTNMBR::' AND CNTCPRSN = '::CNTCPRSN::')
ELSE (CUSTNMBR = '::CUSTNMBR::')
END
ORDER BY ::sortcolumn::
So basically I need to have my select filter on customer number and if customer number is ABC123 then I also need it to filter on Contact person... The problem with the second SELECT (using the CASE statement) is that it throws an "error near =" on the THEN line.
The ::CUSTNMBR:: and ::CNTCPRSN:: are url string variables (What are those called again?).
Ex.
www.mywebsite.com/mypage.asp?Custnmbr=ABC123
Am I going to have to add some logic to the asp page (i.e. IF/Then) to set a variable, and then pass that variable to the *fp_sQry=* line?
I ended up using nested if statements to set the select statement.