I'm developing a website for Tenants to find properties. When they sign up, they can choose the property types that they are interested, for example: Apartment or House.
When a Tenant logs into their account, they can then do a search for properties. The search form is prepopulated with the values that they originally entered on sign up, for example: City, Postcode and so on.
The form also needs to display some checkboxes with the relevant boxes ticked for the Property Types that they selected on sign up. I'm having some problems getting this to work and wondered if there is anyone who could correct the code for me?
I believe I need to use an 'IN' statement so that the relevant checkboxes would be ticked, if the IDs for those properties are found in the CustomerReqPropertyType column. The CustomerReqPropertyType column is varchar(50) and as an example, if a user has selected Apartment and House, it is store in the row as 2, 4 (as there is a separate table with the Property Types.
This is the code I have on the page;
<%
While (NOT rspropertytype.EOF)
%>
<li>
<input type="checkbox" name="txtPropertyType" id="txtPropertyType" value="<%=(rspropertytype.Fields.Item("PropertyTypeID").Value)%>"<% If Not rstenantrequirements.EOF Or Not rstenantrequirements.BOF Then %><%If (Not isNull((rstenantrequirements.Fields.Item("CustomerReqPropertyType").Value))) Then If (CStr(rspropertytype.Fields.Item("PropertyTypeID").Value) = CStr((rstenantrequirements.Fields.Item("CustomerReqPropertyType").Value))) Then Response.Write("")%><% End If ' end Not rstenantrequirements.EOF Or NOT rstenantrequirements.BOF %> />
<label for="txtPropertyType"><%=(rspropertytype.Fields.Item("PropertyTypeTitle").Value)%></label>
</li>
<%
rspropertytype.MoveNext()
Wend
If (rspropertytype.CursorType > 0) Then
rspropertytype.MoveFirst
Else
rspropertytype.Requery
End If
%>
I would be very grateful for any help.
In order for a checkbox to be checked the checked property must equal "checked".
e.g.
<input type="checkbox" name="something" value="somethingElse" checked="checked" />
I suspect that in your code the rspropertytype and rstenantrequirements recordsets could be consolidated into one recordset generated from one SQL statement.
e.g.
SELECT pt.*
, CASE
WHEN ISNULL(tr.CustomerReqPropertyType,0) = 0 THEN 0
ELSE 1 END AS [checked]
FROM propertytype AS [pt]
LEFT JOIN tenantrequirements AS [tr]
ON pt.PropertyTypeID = tr.CustomerReqPropertyType
WHERE ...
Then your ASP code could be simplified as well.
e.g.
<%
While (NOT rs.EOF)
Dim pID : pID = rs("PropertyTypeID")
Dim pTitle : pTitle = rs("PropertyTypeTitle")
Dim checked : checked = "" : If (rs("checked") = 1) Then checked = "checked"
%>
<li>
<input type="checkbox" name="txtPropertyType" id="txtPropertyType<%=pID%>" value="<%=pID%>" checked="<%=checked%>" />
<label for="txtPropertyType<%=pID%>"><%=pTitle%></label>
</li>
<%
rs.MoveNext()
Wend
%>
This is really hard to follow. First I'd break up that line to where your while is you can just set a variable and print that to page. I assume you're trying to set the checkbox checked. What I would do is make sure the value returned isn't null assuming this is a query that just returns the property type and you left joined it with the table that has the descriptions in it when they are set for the property in question. I don't see you ever print checked to the checkbox so it's never going to be checked anyway.
Related
I am trying to query the country column from one of my table and trying to group them so that one country name appears only once.
The controller code is
ViewBag.Countries = (from pT in _context.InfoProducts
group pT by new { pT.Country } into g
select new
{
Country = g.Key.Country
}).ToList();
In my view I am trying to show this list of countries in a dropdown like this
<div class=" form-group">
#Html.Label("Country")
<div class="col-md-12 ">
#Html.DropDownList("Country", new SelectList(ViewBag.Countries, "Country"), "Select Country", new { #class = "col-form-label col-md-12 label-align" })
</div>
</div>
The problem I am facing is though it is returning the expected names of the countries, the result is generating as a key, value pair something like
{Country = USA}
{Country = Canada}
The HTML generated copied from inspect element is given below
<select class="col-form-label col-md-12 label-align" id="Country" name="Country">
<option value="">Select Country</option>
<option>{ Country = USA}</option>
<option>{ Country = Canada}</option>
</select>
How can I get only the country name in the dropdown instead of the result I am currently getting.
Rather than using group by, it sounds like distinct would be a better fit:
_context.InfoProducts.Select(x => x.Country).Distinct().ToList();
This will give you back a list of strings to use, which won't give you the key-value pair problem you're currently having.
One more thing, when you use new SelectList(ViewBag.Countries, "Country") this overload of SelectList's constructor will try to set the value of Country as the selected item, but this doesn't exist in your list, so Select Country will always appear as selected. If you want that to select an actual country, then it would have to look something like:
new SelectList(ViewBag.Countries, "Canada")
where you would fetch Canada from the data for the current product.
I am trying to automate this website using VBA excel. I am stuck at one point where I need to select value from the drop-down box. I am very much new to this as this is my first such project.
This is what I have coded to select the value:
Set objSelect = objIE.document.getElementById("personTitle")
For Each opt In objSelect.Options
If opt.Value = "Miss" Then
'Debug.Print "found!"
opt.Selected = True
'opt.Selected = "selected"
Else
'Debug.Print "not found!"
opt.Selected = False
End If
Next
I have also tried using the debug.print to check if the value that I am trying to find is actually getting matched or not- and it turns out that it matches.
The only problem I am facing is that the value is not getting set.
Can any of the gurus here please help?
Here is the HTML of that section:
<div class="input-wrap input-wrap__inline">
<div tabindex="-1" class="select is-placeholder"><div class="select_display">Title</div><div class="select_arrow glyphicon glyphicon-chevron-down"></div><dl class="select_list"><dt class="pretend-dd is-hover" data-index="1" data-val="Mr">Mr</dt><dt class="pretend-dd" data-index="2" data-val="Mrs">Mrs</dt><dt class="pretend-dd" data-index="3" data-val="Miss">Miss</dt><dt class="pretend-dd" data-index="4" data-val="Ms">Ms</dt><dt class="pretend-dd" data-index="5" data-val="Dr">Dr</dt></dl></div><select name="personTitle" class="parsley-validated hasCustomSelect .no-change, .bv-dropdown-select is-invisible" id="personTitle" required="" data-required-message="Please select a title">
<option selected="selected" value="">Title</option>
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
<option value="Dr">Dr</option>
</select>
</div>
I think you want a different class. The class in that HTML snippet is select_list. Then the subsequent dt tags.
If you observe the following CSS selector, where "." means class and " dt" means select all dt tags inside elements of that class, you will see it makes the correct selections:
In the code below, I translate this selector into:
ieDoc.getElementsByClassName("select_list")(0).getElementsByTagName("dt")
This assumes that index 0 is the correct one to use for elements of the class "select_list". You can easily inspect the collection to find the right index if you set it to a variable e.g.
Dim x As Object
Set x = ieDoc.getElementsByClassName("select_list")(0).getElementsByTagName("dt")
Code:
Dim currentOption As Object
For Each currentOption In ieDoc.getElementsByClassName("select_list")(0).getElementsByTagName("dt")
If InStr(currentOption.innerText, "Miss") > 0 Then
currentOption.Selected = True
End If
Next currentOption
Here are a couple options to try if you haven't already:
If opt.Value = "Miss" Then
'Debug.Print "found!"
opt.Click
OR
If opt.Value = "Miss" Then
'Debug.Print "found!"
opt.Focus
opt.FireEvent ("onchange")
If this turns out to be something done in kendoGrid or kendoDropDownList, I might be able to help with that also.
I decided to rephrase my question to make it a bit easier.
I have a form with three fields
<form class="contact_form" action="divProgramProcess.asp" method="post" name="contact_form">
Couch: <input type="text" name="Couch_Current" id="Couch_Current" />
<br/>
Available:
<input type="text" name="Available_Current" id="Available_Current" />
<br/>
Shipment:
<input type="text" name="Shipment_Current" id="Shipment_Current" />
<input type="submit" value="submit" ></form>
The form calls the following code divProgramProcess.asp (shown below)
<%
divrec = request.QueryString("div")
Set rstest = Server.CreateObject("ADODB.Recordset")
rstest.locktype = adLockOptimistic sql = "SELECT top 1 * FROM CensusFacility_Records WHERE division_program = 'Division 1' and jmsday ='Sun' order by JMSUpdateDateTime desc "
rstest.Open sql, db
%>
<%
Shipment_Current = request.form("Shipment_Current")
Couch_Current = request.form("Couch_Current")
Available_Current = request.form("Available_Current")
rstest.fields("Shipment") = Shipment_Current
rstest.fields("Couch") = Couch_Current
rstest.fields("Available") = Available_Current
rstest.update
Response.Redirect("chooseScreen.asp")
%>
Now keep in mind that the column 'JMSUpdateDateTime" is a date field and there are multiple records of 'Division 1" under the division_program column name.
I'm trying to update the last row in my SQL table but everytime I run this script I only update the first record with "Division 1" not the last record. To put it simply: There are 10 records that contain Division 1. All of them have date timestamp columns. How can I update the last record?
Instead of updating via recordset, run an actual UPDATE Statement. Basicaly you will need 2 steps:
Run your SELECT TOP 1 ... query, but retreive just a primary key/identity field from the table (not " * ") and save it into some temp variable
Run actual SQL "UPDATE CensusFacility_Records SET Shipment = ... WHERE TABLE_ID = " & yourTempVariable
(Best would be to create a parametrized query instead of adding parameters to query string inline). This way you're guaranteed to really update specific record.
Try this:
SELECT * FROM CensusFacility_Records WHERE division_program = 'Division 1'
and jmsday ='Sun' and JMSUpdateDateTime = (SELECT MAX(JMSUpdateDateTime)
FROM CensusFacility_Records WHERE division_program = 'Division 1' and jmsday ='Sun')"
I have a simple search page with this text input form
<form name="assetInput" action="assetResult.jsp" method="get">
<input type="text" name="assetNo" />
<input type="submit" value="Submit" />
</form>
which takes you to a results page that will search an Access database by the Asset Number you type in the search page. The column's data type is number.
This is the code to get the input from the text box, and my attempt to convert the String to an int.
<%
String assetNumber = request.getParameter("assetNo");
int assetNum = Integer.parseInt(assetNumber);
%>
My query:
rs = stmt.executeQuery( "SELECT * FROM [Inventory Tracking] WHERE (([Inventory Tracking].AssetNumber) = '"+assetNum+"')");
I'm able to search columns from the database whose data type is text, but I keep getting errors when trying to search a number column with a String.
Thanks in advance!
Numbers do not take a delimiter, only text fields.
rs = stmt.executeQuery( "SELECT * FROM [Inventory Tracking] WHERE [Inventory Tracking].AssetNumber = "+assetNum);
You could avoid a lot of problems with a parameter.
I don't really know how to deal with the next issue :
So, I've a webbased application developped with ASP.NET MVC3, which is used to remember when an event is relayed to some people.
I've 3 tables
Contact
id_contact
name
firstname
...
event
id_event
...
transmission
FK_id_event
FK_id_firstname
mailed (boolean)
phoned (boolean)
For each event, I need to list all the contacts that are related to this event. And for each contact, I need to display 2 checkboxes that have to be checked if the contact has been called or mailed.
'
' GET: /Event/Details/5
Function Details(id As Integer) As ViewResult
Dim event As event = db.event.Single(Function(o) o.idOpportunite = id)
Dim contacts = (From a In db.contact, b In db.transmission
Where a.id_Contact = b.FK_id_contact And b.FK_id_event = id
Select a)
Dim transmission = (From a In contacts, b In db.transmission
Where a.id_Contact = b.FK_trans_cont
Select b)
Dim model = New EventDetails With {
.event= event,
.Contacts = contacts,
.TransOpp = transopp
}
Return View(model)
End Function
I don't know if the "transmission" part of the code is good or not.
Here in the view, this is were I display the contacts
#For Each contact In Model.contacts
#<tr>
<td>
#Html.ActionLink(contact.name + " " + contact.firstname , "Details", New With {.id = contact.idContact})
</td>
<td>
#Html.Raw(contact.phone)
</td>
<td>
#*Html.DisplayFor(Function(modelItem) currentItem.mail)*#
<a href=mailto:#contact.mail>#Html.Raw(contact.mail)</a>
</td>
<td>
***My checkboxes should be here***
</td>
</tr>
Next
So, my question is, what should I do to display those checkboxes?
(sorry if I'm not understandable, I'm not a native english speaker. Don't hesitate to edit my english mistakes (or the title which is not a great one)).
With the help of Yasser, I've done this :
#code
Dim mail As Boolean = (From a In Model.Event
Where a.FK_id_contact = contact.idContact And a.FK_id_event = Model.Opportunite.idOpportunite
Select a.mailed)
End Code
However, I get an error :
Value of type 'System.Collections.Generic.IEnumerable(Of Boolean)' cannot be converted to 'Boolean'.
Here is something that should help
#{
bool isMailed = // set values;
bool isPhoned = // set values
}
#Html.CheckBox("mailed ", isMailed );
#Html.CheckBox("phoned", isPhoned );
In your ContactViewModel you can have two properties
bool isMailed ;
bool isPhoned ;
Then you can query the database from your controller before you bind the viewmodel the view and set those parameters. For example if you are showing data for contact id = 1 and event id = 2, you can query the database table transmissions and find whether you have called or mailed before and update the variable in ContactViewModel.
then in your view you can bind the values to the checkbox as follows
#Html.CheckBox("mailed ", contact.isMailed );
#Html.CheckBox("phoned", contact.isPhoned );
if you want to update the mailed or phoned in the database you can do it using the above ViewModel by submitting data to the controller. from controller you can find what is the Event_Id, Contact_Id and mailed or phoned , then you can update the database accordingly