create html through C# code in PageLoad - html

Basically, I have a "Posts" DataTable with multiple rows.
Each row contains fields like "UserID", "PostBody", "PostDate", "UploadedFileID" etc.
What I'm trying to achieve is a "News" page, where users can see all the posts from the DataTable.
So if I have 5 rows, i want for each row to have an HTML Structure like:
<div id="post">
<h3>User name (based on the UserID row)</h3>
<div id="postBody">
bla bla bla whatever the user posted
</div>
<a href="(link to the posted file)">
<img src="something" />
</a>
</div>
I'm thinking that inside the .aspx file, in the PageLoad event I have to make a while loop, like:
while (there are posts in the posts table)
write html;
How do I add HTML-building conditions, and more importantly, paging?
Thanks,
Tudor.

You could use one of the several data binding controls and put your html structure into the template.
Refer: Asp.net DataBound controls
Ones like the Repeater or ListView should give you what you want.
<asp:ListView runat="server" ID="ListView1"
DataSourceID="PostsDataSource" >
<ItemTemplate>
<div id="post">
<h3>User name (based on the UserID row)</h3>
<div id="postBody">
<asp:Label ID="LastNameLabel" runat="Server"
Text='<%#Eval("PostBody") %>' />
</div>
<a href="(link to the posted file)">
<img src="something" />
</a>
</div>
</ItemTemplate>
</asp:ListView>
Code behind:
ListView1.DataSource =
The advantage of using a data binding control is that asp.net will manage the paging and value binding.

Related

CSS Selector / XPath needed for accessing a <span>

I'm doing a scrapy project in which I try to extract data on sponsored TripAdvisor listings (https://www.tripadvisor.com/Hotels-g189541-Copenhagen_Zealand-Hotels.html).
This is how the html code looks like
<div class="listing_title ui_columns is-gapless is-mobile is-multiline">
<div class="ui_column is-narrow">
<span class="ui_merchandising_pill sponsored_v2">Sponsored</span>
</div>
<div class="ui_column is-narrow title_wrap">
<a target="_blank" href="/Hotel_Review-g189541-d206753-Reviews-Scandic_Front-Copenhagen_Zealand.html" id="property_206753" class="property_title prominent " data-clicksource="HotelName" onclick="return false;" dir="ltr"> Scandic Front</a>
</div>
</div>
I was able to successfully retrieve elements such as the link, id, name with constructs such as response.css(".listing_title").css("a::text").extract().
However, I have trouble retrieving anything from the "Sponsored" -tag attached to the accommodation listings - result is an empty list despite there being two listings with the "Sponsored"-tag on the website.
I tried response.css(".sponsored_v2").css("::text").extract()without any success.
What can I do ?
It looks like you have a typo, try changing .exctract to .extract, you have an extra c.

Kentico - Adding an anchor tag in a repeater transformation

I have an Accordion Tab repeater that I would like to add an anchor tag to each unique title within the transformation.
Here is my code:
<li>
<a href="#tab-<%# DataItemIndex+1%>-<%# Container.Parent.Parent.ClientID %>" title="<%# Eval("Title") %>">
<span class="tab-item-title"><%# Eval("Title") %></span>
<span class="ui-icon"></span>
<%# String.IsNullOrEmpty(Eval<string>("MainText")) ? "" : "<div class=\"tab-item-subtitle\">" + Eval("MainText") + "</div>" %>
</a>
</li>
I tried adding:
<a id="<%# Eval("AnchorLinkName") %>" name="<%# Eval("AnchorLinkName") %>"></a>,
but it didnt work.
No need to post this in both the DevNet and SO. The DevNet automatically includes SO posts tagged as "kentico". Reference original answer here:
https://devnet.kentico.com/questions/adding-an-anchor-tag-in-a-repeater-transformation
Typically what you do in this case is have a datasource web part on the page and specify the necessary fields (where, page types, order by, etc.). You take note of the datasources name and add that to two repeaters on the page. One repeater is or your anchor link navigation and the other is the actual content you wish to display (link to).
One thing to note, is the anchor link needs to be a URL friendly value. So something with spaces or un-encoded URL values will NOT work.
In your navigation repeater (where you link FROM), you'll need something like the following in the transformation:
<li>
<%# Eval("DocumentName") %>
</li>
In your listing repeater (where you link TO), you'll need something like the following in the transformation:
<div class="faq-item" id="faq-<%# Eval("DocumentID") %>">
... your content here
</div>
Reference W3Schools Bookmarks

new document dialog showing master page header images

I have a SharePoint team site and I made some changes in master page as below:
Moved top menu links and search box below page heading
In place of top links I placed an image called image1 and in place of search box I placed another image called image2
Replacing SharePoint logo with my own logo and increasing its size
I did all this using DIV/CSS. Now I am no designer, not even close. So I had to do a lot of trial and error before every thing looked ok except this one issue which now I am facing and i.e. when you click on "new document" link which opens a dialog box where you can upload document, that window is also showing those logos (which I mentioned in point 2 above)
How can I get rid of that? I was thinking that if somehow I can find out if the dialog is open then I can hide those images using CSS/Jquery?
Here's partial code to given you and understanding where I have wrote code. My divs are named "mydiv" and "mydiv2" while rest of the code is SharePoint's default:
<div id="WebPartAdderUpdatePanelContainer">
<asp:UpdatePanel
ID="WebPartAdderUpdatePanel"
UpdateMode="Conditional"
ChildrenAsTriggers="false"
runat="server">
<ContentTemplate>
<WebPartPages:WebPartAdder ID="WebPartAdder" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="WebPartAdder" />
</Triggers>
</asp:UpdatePanel>
</div>
</SharePoint:AjaxDelta>
</div>
</div>
<div id="s4-workspace" class="ms-core-overlay">
<div id="mydiv" style="float:left;border:thin;border-style:none;width:210px;position:absolute; padding-top:20px;padding-bottom:0px;padding-left:200px;z-index:1;">
<img src="/images/image1.jpg" width="65%" height="65%"></div>
<div id="mydiv2" style="border: thin none currentColor; width: 250px; right:600px;position:absolute; padding-top:20px; padding-bottom:10px;float: right;z-index:1;">
<img src="/images/image2.jpg" width="800" height="56">
</div>
<div id="s4-bodyContainer">
<div id="s4-titlerow"
class="ms-dialogHidden s4-titlerowhidetitle">
<div id="titleAreaBox"
class="ms-noList ms-table ms-core-tableNoSpace">
<div id="titleAreaRow"
class="ms-tableRow">
Fixed by using CSS class ms-dialogHidden as mentioned here:
https://sharepoint.stackexchange.com/questions/200195/new-document-dialog-showing-master-page-header-images/200197#200197

asp tags don't get rendered in a form

I have a masterpage that contains an application form, it has a set of questions on it and then right at the end it's supposed to have between 0 and 5 additional questions depending on the position applied for. Here's the code snippet from the Apply.Masterpage file:
<div class="row">
<label>Please specify the main 3 software languages / technologies you have worked with in the last 5 years, and at what level you would rate yourself (between 1 and 5 where 1 is poor and 5 is excellent) *
<asp:TextBox ID="QuestionC" runat="server" TextMode="MultiLine" Rows="10"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionCRequired" ControlToValidate="QuestionC"
ErrorMessage="Please provide a mobile phone number." runat="server" />
</label>
</div>
and this is fine, prints the text box with working validator and a label, however the problems starts with the code that 's placed right below it:
<%
string[] questions = new string[] { "question1", "question2", "question3", "question4", "question5" };
foreach (var question in questions)
{
if(!(umbraco.library.GetItem(question).Equals("", StringComparison.Ordinal)))
{
var questionRequired = (question + "Required");
%>
<div class="row">
<label><%:question%>+<%:umbraco.library.GetItem(question)%>
<asp:TextBox ID=<%:question%> runat="server" TextMode="MultiLine" Rows="10"></asp:TextBox>
<asp:RequiredFieldValidator ID=<%:questionRequired%> ControlToValidate=<%:question%>
ErrorMessage="Please anwer the question" runat="server" />
</label>
</div>
<%}
}%>
which is supposed to print two additional textboxes, but it prints:
question1+ksdgfjsdgfjsdg
question2+jugkjfkhfkhg
Where question1 is a name of field in Umbraco and "ksdgfjsdgfjsdg" is the actual question, so it picks the right data from Umbraco, but it seems like it skips the asp tags which is strange because the work fine a couple of lines above. The only difference is the use of <% %> tags in the additional question. How do I make the text box appear? I was trying to put the code responsible for printing additional questions in the macroScript but I only got as far as I am now.
I could be totally wrong here, but I'm not sure you can dynamically create asp.net textboxes in this way. That's why it's only giving you the items immediately after the label tag.
I think if you want to dynamically create them you have to do something like
myTextBox = new TextBox();
myTextBox.ID = "txtIDGoesHere";
PanelForMyTextBox.Controls.Add(myTextBox);
But I may have misunderstood the question.

JSF dataTable as CSS table with clickable rows?

Related questions have been asked but as there is not as yet any solid/acceptable answer, I thought I would re-phrase and clarify:
Is there a way within JSF to populate a dataTable or related query-result component without re-writing renderers as a W3C CSS table? This must enable clickable rows and row (versus column) styling a:hover, etc.
Example of desired rendered JSF component HTML from a query:
<div class="table">
<a href="#" class="row">
<span class="cell">Column-1-Value</span>
<span class="cell">Column-2-Value</span>
</a>
...
</div>
Thanks to the input provided, this is the complete answer (versus just in comments) tested in a Java EE/JSF container:
<div class="table">
<ui:repeat value="#{BackingBean.list}" var="item">
<h:outputLink value="url">
<f:param name="ID" value="#{item.ID}"/>
<span class="cell">#{item.ID}</span>
<span class="cell">#{item.Name}</span>
</h:outputLink>
</ui:repeat>
</div>
The above can then be styled using CSS/3 display:table, display:table-row and display:table-cell; respectively. Row is clickable and can be styled as desired.