How to add class dynamically inside a loop using asp - asp-classic

I want to add a class for Masonry in the loop while.
What can I do for loop should be only one?
Is output to the three data three times.
Is there another way?
<div id="box-container">
<div class="grid-sizer"><!-- avl for packery to get grid size --></div>
<%
'creates an array
Dim x, y, z
x = Array("w2 h1", "w1 h2", "w1 h1")
rso()
cate = "fo01"
SQL = " SELECT TOP 3 * FROM ms_dbtable WHERE category = '"& cate &"' ORDER BY sort_idx ASC "
rs.open SQL, dbcon, 3
If Not rs.eof Then
While Not rs.EOF
For Each y In x
%>
<div class='box snip1328 <%=y%>'>
<% If rs("thumb") = "" Then %>
<img src="/img/tlogo.gif"></a>
<% Else %>
<img src="/data/fo01/<%=rs("thumb")%>"></a>
<% End If %>
</div>
<%
Next
%>
<%
rs.MoveNext
Wend
End If
rsc()
%>
<style>
.w1 {width: 138px;}
.h1 {height: 138px;}
.w2 {width: 280px;}
.h2 {height: 280px;}
.w3 {width: 422px;}
.h3 {height: 422px;}
</style>
The result is output as a duplicate image.
The output data has Blurring the face picture.
enter image description here

Since you are selecting TOP 3, and there are three elements in the array,
you could move the array index within the loop using a counter.
If Not rs.eof Then
Dim xindex : xindex=0
While Not rs.EOF
%>
<div class='box snip1328 <%=x(xindex)%>'>
<% If rs("thumb") = "" Then %>
<img src="/img/tlogo.gif"></a>
<% Else %>
<img src="/data/fo01/<%=rs("thumb")%>"></a>
<% End If %>
</div>
<%
xindex = xindex + 1
rs.MoveNext
Wend
End If

Related

How to create a dynamic grid with different column widths

I'm using Bootstrap 3 and Rails.
I have a Model called Work, with many records.
I would like to create a dynamic grid on which the column widths vary depending on its row. Something Like this:
My erb view:
<ul class="row">
<% #works.each do |s| %>
<li class="col-sm-4"><%= s.name %></li>
<% end %>
</ul>
This way, each li element will have a col-sm-4 width everytime.
I need to tell Rails "Every 4 elements change the column width to x..."
Any help? Thanks!
Something like this:
<% #works.each_with_index do |s,index| %>
<li class="col-sm-<%= index%4 == 0 ? '4': '6' %>"><%= s.name %></li>
<% end %>
I finally used your each_with_index to customize the layout as it follows:
<% #services.each_with_index do |s, index| %>
<% if index < 2 %>
<li class="col-sm-6"><%= s.name %></li>
<% elsif index.between?(2,4) %>
<li class="col-sm-4"><%= s.name %></li>
<% elsif index > 4 %>
<li class="col-sm-6"><%= s.name %></li>
<% end %>
<% end %>
Thanks!!

Creating article pagination

Hi I'm using silverstripe 2.4.7 and I'm having difficulty getting the pagination to work. I've created a function in my page.php to get the latest articles like so
function AllNewsPosts($num=1) {
$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsEntry", "ParentID > 0", "Date DESC", "", $num) : false;
}
Then when i put this function into the control and pagination tags one article shows up however the links to the concurrent articles do not work - essentially the pagination is not working and I'm not sure how to fix it
<% if AllNewsPosts %>
<% control AllNewsPosts %>
<div class="event">
<h2>$MenuTitle |<span class="date"> $Date.Time $Date.Long</span></h2>
<p>$Content.FirstParagraph</p>
See more about this event
</div>
<% end_control %>
<% else %>
<div class="no-entry">'There are no entries'</div>
<% end_if %>
<% if AllNewsPosts.MoreThanOnePage %>
<div id="PageNumbers">
<p>
<% if AllNewsPosts.NotFirstPage %>
<a class="prev" href="$AllNewsPosts.PrevLink" title="View the previous page"><span class="yellow-background">Prev</span></a>
<% end_if %>
<span>
<% control AllNewsPosts.PaginationSummary(0) %>
<% if CurrentBool %>
<span class="current">$PageNum</span>
<% else %>
<% if Link %>
$PageNum
<% else %>
…
<% end_if %>
<% end_if %>
<% end_control %>
</span>
<% if AllNewsPosts.NotLastPage %>
<a class="next" href="$AllNewsPosts.NextLink" title="View the next page"><span class="yellow-background">Next</span></a>
<% end_if %>
</p>
</div>
<% end_if %>
Any help is much appreciated
Note: The following answer is for Silverstripe 2.4. This should not be used for Silverstripe 3.0+ sites. From 3.0 and onwards the PaginatedList object makes pagination much easier.
You are not setting a limit on how many entries to retrieve in your query, or where to start from.
The following tutorial explains how to apply pagination to a set of data objects exactly as you are trying to do:
http://www.ssbits.com/tutorials/2010/paginating-a-filtered-dataobjectset/
Here is an attempt at altering your function to include limit and start as needed for pagination:
PHP
function AllNewsPosts() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1)
{
$_GET['start'] = 0;
}
$SQL_start = (int)$_GET['start'];
$newsEntries = DataObject::get('NewsEntry', '', 'Date DESC');
$doSet = new DataObjectSet();
foreach ($newsEntries as $newsEntry) {
if ($newsEntry->canView()) {
$doSet->push($newsEntry);
}
}
$doSet->setPageLimits($SQL_start, 10, $doSet->Count());
return $doSet;
}
Note the above will display 10 items per page. You can change this to however you need per page.

ASP Alternating CSS Issue

Currently I have 4 spans with alternating CSS tags.
<% var index =0 ; %>
<% foreach (var item in Model.Take(4)) {
var css = (index%2==0)?"even":"odd";
%>
<span class="featured-products <%= css %>">
<%= Html.Photo(PhotoExtensions.PhotoSizeType.HomepageThumb, item.DefaultPhoto)%>
<%= item.ProductName%>
</span>
<%
index ++ ;
} %>
But I need for the last span to contain an extra CSS tag "last". Ive tried a couple of different methods but they all failed. Any help? Thanks.
Have you tried using the :last-child CSS selector? It may not be necessary to add additional markup if you can achieve what you want through CSS.
If you don't want to use CSS.
<% var index = 0; %>
<% var items = Model.Take(4); %>
<% foreach (var item in items) {
var css = (index%2==0)?"":"odd";
if(index == items.Count - 1)
{
css = " last";
}
%>
<span class="featured-products <%= css %>">
<%= Html.Photo(PhotoExtensions.PhotoSizeType.HomepageThumb, item.DefaultPhoto)%>
<%= item.ProductName%>
</span>
<%
index ++ ;
} %>
Also, I would recommend cleaning this code up. You don't need to put <% and %> everywhere.
Update: A bit cleaner way of writing what you're doing. Definately not the cleanest but a good start.
<%
var index = 0;
var items = Model.Take(4);
foreach (var item in items) {
var css = (index%2==0)?"":"odd";
if(index == items.Count - 1)
{
css = " last";
}
%>
<span class="featured-products <%= css %>">
<%= Html.Photo(PhotoExtensions.PhotoSizeType.HomepageThumb, item.DefaultPhoto)%>
<%= item.ProductName%>
</span>
<%
index ++ ;
}
%>

classic asp to asp.net conversion

hi i am working on project jigsaw puzzle game . i have done with coding in classic asp using vb script and it working properly . i want to do same coding asp.net using vb.net but css style i was written it was not working properly in asp.net can anybody help me doing this conversion.
<html>
<head>
<script type="text/javascript">
function setText(pieceID)
{
if (document.getElementById("first").value == '' )
{
document.getElementById("first").value=pieceID;
}
else
{
document.getElementById("second").value=pieceID;
document.swap.submit();
}
}
</script>
</head>
<body>
<%
dim img
img = "img1.jpg"
%>
<div class="classname"> <img src="<%response.write img%>"> </div>
<%dim imgPIX
imgPIX = 60
%>
<style>
.icons { display: block; width: <%response.write imgPIX%>px; height: <%response.write imgPIX%>px; background-image: url(<%response.write img%>); background-repeat: no-repeat; }
<%
dim proper
dim ico_number,col
dim row_number,rw
for row_number = 1 to 6
rw = (row_number - 1) * (-1 * imgPIX)
for ico_number = 1 to 6
col = (ico_number - 1) *(-1 * imgPIX)
response.write ".icon"& row_number &"_"& ico_number &" { background-position: col &"px "& rw &"px; } "
if not proper = "" then
proper = proper & "," & row_number &"_"& ico_number
else
proper = row_number &"_"& ico_number
end if
response.write ".icon"& row_number &"_"& ico_number &" { background-position: 0px 0px; } "
next
next
%>
</style>
<%
dim userfeed
if request.form("userform") = "" then
userfeed = random_sort(proper)
end if
if request.form("first") <> "" and request.form("second") <> "" then
userfeed = request.form("userform")
userfeed = replace(userfeed,request.form("first"),"temp1")
userfeed = replace(userfeed,request.form("second"),"temp2")
userfeed = replace(userfeed,"temp1",request.form("second"))
userfeed = replace(userfeed,"temp2",request.form("first"))
end if
%>
<center>
<form name="swap" action="default.asp" method="post">
<input type="hidden" name="first" ID="first">
<input type="hidden" name="second" ID="second">
<input type="hidden" name="userform" ID="userform" value="<%response.write userfeed%>">
</form>
<table border="0">
<%
if userfeed = proper then
%>
<H1>Solved !!</h1>
<%
end if
dim icoarr
icoarr = split(userfeed,",")
dim ctr
ctr =0
for each piece in icoarr
if ctr =6 then
response.write "<tr>"
end if
%>
<td><span class="icons icon<%response.write piece%>" style="float:left;" onclick="setText('<%response.write piece%>')"></span></td>
<%
if ctr =6 then
ctr =1
else
ctr = ctr + 1
end if
next
%>
<%public function random_sort(arrySTR)
arrySTR = arrySTR & ","
dim retstr
do while arrySTR <> ""
dim arr
arr = split(arrySTR,",")
dim random_number
randomize
random_number=int(rnd*(ubound(arr)-1))+0
'response.write random_number
retstr =arr(random_number) & "," & retstr
arrySTR = replace(arrySTR,arr(random_number) & ",","")
loop
retstr = mid(retstr,1,len(retstr)-1)
'response.write "<br>" & retstr
random_sort=retstr
end function
%>
</table>
</body>
You can try Asp.Net WEBMATRIX tool for converting the same code to Asp.Net with minimal effort
http://www.asp.net/web-pages

writing output to a dropdown list

<%
dim req_id
req_id=Request.Form("Req_id")
Set conn=server.CreateObject("adodb.connection")
conn.Open session("Psrconnect")
Set rs=CreateObject("Adodb.Recordset")
rs.Open "select * from releases where project like '%"&req_id&"%'", conn
%>
<SELECT style="LEFT: 454px; WIDTH: 500px; TOP: 413px" name="txtrelease1" id="txtrelease1">
<%
if rs.EOF=true then
%>
<OPTION value="NO Request to Edit">No Request to Edit</OPTION>
<% else
do while rs.EOF<>true
p=InStrRev(rs.Fields(0),"\")
q=Len(rs.Fields(0))
r=(Right(rs.Fields(0),(q-p))) %>
<OPTION value=<%=rs.Fields(0)%>> r </OPTION>
<%
rs.movenext
loop
end if
%>
</SELECT>
i want to right the value of r in the dropdown list. i dont know the syntax. as of now the drop down list shows "r" , not the value inside it. how to do it?
This should do it:
do while not rs.EOF
p=InStrRev(rs.Fields(0),"\")
q=Len(rs.Fields(0))
r=(Right(rs.Fields(0),(q-p)))
%>
<option value="<%=rs.Fields(0)%>"><% =r %></option>
<%
rs.moveNext
loop

Resources