i'm trying to print a record in NVelocity based on certain condition:
Below is the snippet... basically, Loop through the Addresses Object and if the current AdType is the "Current Address", print it and then exit out of the loop ...
I'm getting "#break" in my output html... as if it is ignoring it..
I have version 1.1.1 of NVelocity
Thanks
#foreach($spAddress in $Report.Spouse.Addresses)
#if( $spAddress.AdType == "Current Address")
<tr>
<td width="23%">
<font size="2"><strong>$spAddress.AdType :</strong></font>
</td>
<td width="75%">
<font size="2">$spAddress.CivicNumber, $spAddress.StreetName,$spAddress.City, $spAddress.Province, $spAddress.PostalCode</font>
</td>
</tr>
#break
#end
#end
I implemented #break about a year ago, but it's not in any released version yet. You can get it from the Monorail2 repository. Give it a try and let us know if you find any bugs.
Related
I need the value of the selected item in an html select element. Here the accepted answer recommends doing it like so:
Request.Form["testSelect"]
So in my case, I've got this html select element:
<select name="subcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
<% if Not IsNewBusiness then %>
<option <% If subcategory = "0" Then Response.Write(" selected")%> value="0">Existing
<option <% If subcategory = "1" Then Response.Write(" selected")%> value="1">Organic Growth
<% else %>
<option <% If subcategory = "0" Then Response.Write(" selected")%> value="0">New
<option <% If subcategory = "1" Then Response.Write(" selected")%> value="1">Assumed
<% end if %>
</select>
Yet the design-time compiler is not happy with it, as can be seen by the squiggles beneath "Request.Form" and the whiteness of "subcategory":
What do I need to do to grab that value from VB.NET?
UPDATE
When I tried what Sailor suggested in his answer (added "runat="server"" to the html select element), I got:
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following
specific parse error details and modify your source file appropriately.
Parser Error Message: Server tags cannot contain <% ... %> constructs.
Source Error:
Line 744: </td>
Line 745: <td nowrap align="left" valign="top">
Line 746: <select runat="server" name="subcategory" color="<%=Session
("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
Line 747: <% If Not IsNewBusiness Then%>
Line 748: <option <% If Subcategory = "0" Then Response.Write(" selected")%>
value="0">
Source File: /EMS/customerreportingnet/pages/custmaint_entry.aspx Line: 746
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
Removing it obliterated the err.
UPDATE 2
This:
Subcategory = Request.Form.Item("selectSubcategory")
...is giving me the index of the selected item (such as "0"); how can I get the actual text instead?
UPDATE 3
It turns out that it's not really giving me the index of the selected item, after all - it is simply giving me "0" always - whether the first (0th) or second (1st) option is selected.
If I try what is mentioned at the outset, using this kind of code:
Subcategory = Request.Form["selectSubcategory"]
I get this error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30311: Value of type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'String'.
Source Error:
Line 90: CustNo = Request.Form.Item("CustNo")
Line 91: 'Subcategory = Request.Form.Item("selectSubcategory").ToString() '<= question at https://stackoverflow.com/questions/42655000/how-can-i-reference-the-selected-item-in-an-html-select-element-vb-net
Line 92: Subcategory = Request.Form["selectSubcategory"]
Line 93: AutoID = Request.Form.Item("AutoID")
Line 94: ReturnMsg = ""
Source File: C:\Users\cshannon\Source\Workspaces\CSReports\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 92
That's why I went the other route, with:
Subcategory = Request.Form.Item("selectSubcategory").ToString()
...but that's not quite cutting the mustard, either (just returning 0 always).
Make sure you have runat="server" in your form tag. Otherwise keep it in the Select tag.
And then try using
Request.Form.Item("Subcategory")
How can I do change Order Status field.
For example ; I want do if the data name "AÇIK" change name "OPEN". How can I do.
<td><%#DataBinder.Eval(Container.DataItem,"OrderStatus") %></td>
<%#(DataBinder.Eval(Container, "OrderStatus").ToString()=="AÇIK") ?
"OPEN":DataBinder.Eval(Container, "OrderStatus")%>
I have a page with the following html.
<table id="batting_gamelogs">
<tbody>
<tr class id="batting_gamelogs.153">
<td></td>
<td></td>
<td>
<span id="PHA192504150-simmoal01">
</td>
</tr>
<tr class id="batting_gamelogs.154">
<td></td>
<td></td>
<td>
<span id="PHA192504160-simmoal01">
</td>
</tr>
<tr class ="thead">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
I am using the following code to scrape the table.
data = NULL
batlist = NULL
battingURLs <- paste("http://www.baseball- reference.com",yplist[,c("hrefs")],sep="")
for(thisbattingURL in battingURLs){
batting <- htmlParse(thisbattingURL)
fstampid <- regexpr("&", thisbattingURL, fixed=TRUE)-1
fstampyr <- regexpr("year=", thisbattingURL, fixed=TRUE)+5
id <- substr(thisbattingURL, 53, fstampid)
year <- substr(thisbattingURL, fstampyr, 75)
if (length(xpathSApply(batting, '//*[#id = "batting_gamelogs"]', xmlValue))==0) next
tableNode <- xpathSApply(batting, '//*[#id="batting_gamelogs"]')[[1]]
data <- readHTMLTable(tableNode, stringsAsFactors = FALSE)
data # select the first table
total <- cbind(id,year,data)
batlist <- bind_rows(batlist, total)
}
I would like to leave out any row with the class "thead". I don't know if it would be easier to scrape the whole table and then delete the unwanted rows later or just not grab them in the first place. I would also like to assign the span id to a variable called gameid for each row in the table I scrape.
The code I am using to scrape the table grabs the whole table at once I think, but I'm not sure as I'm new to R. I've tried searching here, but I can't make heads or tails of anything I have found.
The code I'm using to set the gameid works when I test with one URL and choose a specific tr class id, but doesn't when I use contains. I'm not sure if it's because I'm running in a loop and scraping the whole table at once or not.
gameid <- xpathSApply(batting, '//*[#id="batting_gamelogs.153"]/td[10]/span/#id')
returns this "PHA192504150-simmoal01" and it will be different/unique for every row of the table.
When I run in the loop I'm trying the following code
gameid <- xpathSApply(batting, '//*[contains(., "batting_gamelogs."]/td[10]/span/#id')
From there I'll just cbind gameid with the other variables at the end of the code. I don't have it in there now because it's not working.
Thanks for any help, it is greatly appreciated!!
I was able to pull the gameid from the table by correcting the code like #har07 suggested and switching the . to #id in the contains.
gameid <- xpathSApply(batting, '//*[contains(., "batting_gamelogs.")]/td[10]/span/#id')
now looks like
gameid <- xpathSApply(batting, '//*[contains(#id, "batting_gamelogs.")]/td[10]/span/#id')
I was also able to exclude rows by subsetting the current data.frame. I added this line of code to create a new data.frame without useless headers and misc rows.
newdata <- subset(data, Rk!="April" & Rk!="May" & Rk!="June" & Rk!="July" & Rk!="August" & Rk!="September" & Rk!="October" & Rk!="November" & Opp!="<NA>")
I am looking to evaluate two strings from my dataset to identify a class description using a ternary operator.
I continue to get a compiler error when running this code stating that "Expression Expected".
I think that it has to do with the comparison of strings but I have tried other comparison operators and can't seem to get it to work.
<ItemTemplate>
<tr>
<td><%# FormatDateTime(Eval("GameDate"), DateFormat.ShortDate)%></td>
<td class="<%# (Eval("Team1Score").ToString() > Eval("Team2Score").ToString()) ? 'Winner':'' %>"><%# Eval("Team1")%></td>
<td><%# Eval("Team1Score")%></td>
<td><%# Eval("Team2")%></td>
<td><%# Eval("Team2Score")%></td>
</tr>
</ItemTemplate>
Here is my sample data:
GameDate Team1 Team1Score Team2 Team2Score Winner
2012-04-14 Blues 5 Reds 3 Blues
2012-04-13 A's 4 B's 2 A's
2012-04-11 Blues 1 A's 1 Tie
2012-04-13 B's 3 Reds 2 B's
2012-04-10 Blues 7 B's 4 Blues
Thank you for your help
I think the problem is that you are trying to do comparison between two strings. Just convert the values to a int or something similar for comparison. So for example, change your comparison to something like the below:
<td class="<%# (Convert.ToInt32(Eval("Team1Score")) > Convert.ToInt32(Eval("Team2Score"))) ? 'Winner':'' %>"><%# Eval("Team1")%></td>
Or you can just cast it to the appropriate type:
<td class="<%# ((int)Eval("Team1Score") > (int)Eval("Team2Score")) ? 'Winner':'' %>"><%# Eval("Team1")%></td>
Hope this helps!
Try this
<%#Eval("Status").ToString()=="1" ? "ClubMember" : "Free User" %>
<asp:Repeater ID="rptLessons" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("fullname")%></td>
<td><%#isCompleted(Eval("totallessons"), Eval("completedlessons"), Eval("totalNumAvail"), Eval("totalNumCorrect"))%></td>
<td><%#FormatPercent(Eval("totalnumcorrect") / Eval("totalNumAvail"))%> <%-- (<%#Eval("totalnumcorrect")%> / <%#Eval("totalNumAvail")%>) --%></td>
<td><%#FormatPercent(Eval("completedlessons") / Eval("totallessons"))%> <%-- (<%#Eval("completedlessons")%> / <%#Eval("totallessons")%>) --%></td>
<td><%#Eval("lastaccessed")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
I can't figure it out but as soon as it hits some NULL data it refuses to move on to drawing the next elements.
You need to give a stack trace to be sure.
But I can see several issues:
DIV#0 errors inside FormatPercent
NULL errors.
Example Solution
(System.Convert.ToInt32 should convert DBNull/NULL to 0)
Or alter isCompleted to accept Object paramters and do your NULL / DBNull checking inside the function.
On slightly different approach that might be helpful would be to do your computations in your code behind rather than inline in the markup. Just easier to check for nulls etc. I almost always go down this path with anything other than a simple Eval() in my markup.
<td>
<%#GetCorrectPercent()%>
</td>
protected string GetCorrectPercent()
{
if(Eval("totalnumcorrect") == null || Eval("totalNumAvail") == null)
return "n/a";
return ((int)Eval("totalnumcorrect") / (int)Eval("totalNumAvail")).ToString();
}
Not sure all the formatting is correct here but this should get you going in a different direction. Eval() will work within the called methods so long as the caller is current performing a DataBind().
If I had to guess, I would say that your isCompleted function doesn't handle values of Nothing. This is a guess because the function hasn't been listed in your example.
I tend more towards the explicit. Forgive any minor mistakes in the code, I'm not able to test this.
If in your markup you swap out those evals for literals then in the code behind:
If you have a collection of MyClass.
In your page's init event
this.rptLessons.OnItemDataBound += rptLessons_DataBound...
In the load or where ever you choose
this.rptLessons.DataSource = CollectionOfMyClass;
this.rptLessons.DataBind();
Then in that itemDataBoundEvent
MyClass myClass = (MyClass)ri.DataItem;
Literal litFullname = FindControl(ri, "litFullName");
litFullName.Text = myClass.Fullname;
This way you can cater for nulls etc in a more controlled way than using eval.