Is it possible to auto increment repeater control? - asp.net

I have a repeater control on my web page that displays images as a result of a search. The user searches for a keyword, and my program stores the search results in a data table. The repeater then displays the images in the data table. So, if there are 150 images in the data table, the repeater will display all 150 images. Here's the code for my repeater:
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style="background-color: Silver; border-style: solid; display: inline-block;
float: left; margin: 5px; overflow: hidden;">
<div style="text-align: center">
<asp:Label ID="lblImage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "image") %>'></asp:Label>
</div>
<div>
<%# DataBinder.Eval(Container.DataItem, "url") %>
</div>
<div style="text-align: center;">
<asp:HyperLink ID="requestLink" runat="server" Text="Original" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "requestUrl") %>'>
</asp:HyperLink>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
What if, however, I don't want to display all 150 images? Is there a way to only display, say, 20 at a time and let the repeater auto expand when the user scrolls down or hits a 'MORE' button, or something like that?
Thanks!

For that you have to search for auto refresh or scroll event of mouse.
for auto refresh you can write this kind of code in javascript using that you can reload page after every interval
<script type="text/javascript">
setInterval(function () {
load()
}, 30000);
var load = function () {
location.reload();
};
</script>
and on Load event of page you have to rebind data to repeater.

Related

How to show a loading spinner when loading another aspx using asp.net and visual studio?

I know this question has been asked many times, but I didn't seem to find any solution that I can understand online. Most says using javaScript and css but I don't really know how to implement that.
I'm using visual studio and i have a master page and several other content pages. On the master page I have a link that redirects me to one of these content pages using
"a href = pages.aspx"
Since the content page uses a SQL query to retrieve data so it takes a very long time. I would like to show a loading spinner or progress bar or even just a text saying "loading..." while the page loads.
Are there anyway to do this?
I also thought about using a label which is only visible when the link is clicked, and goes invisible when the page loads. Is there a way of doing this?
Thanks!
An exact situation with detailed code and explanation, where a loading image is shown on loading of an asp.net page can be seen at following URL : Show Loading Image when Page first Loads.
This has detailed explanation with full working code as well as a link to demo page. You can ask me if you have any questions regarding this sample.
To verify that the loading image shows up in above sample you can simply go to this URL : Loading Image when Page first loads
Another very simple approach with tested/tried sample code is as explained below.
You will need jquery in your aspx page for this to work.
There are three scenarios in which you would like to show a loader element in an aspx page and they are:
On button click that does a non-ajax postback
hyperlink click that navigates to another page
on button click that does an ajax postback
In first two of above scenarios, all you need to do is hookup their client click event with a JavaScript method of ShowProgress. This method shows a popup div that has an animated image in it.
In the last scenario where an ajax postback is done, an UpdateProgress control is used so it automatically hides once the ajax postback completes.
The loader popup is styled to show at center of page in a modal manner'; these styles can be found in the head section of markup pasted below. You can modify some of these styles like border or background-color and also you can substitute any animated image in place of loading.gif.
I tested the markup below with a Page PageTakingLongToLoad.aspx that took 20 s to load the first time it rendered, and with ajax/non-ajax postbacks that took 10 s to complete, and in both cases the loader displayed perfectly as expected.
Markup of Page from which a loader is shown
<%# Page Language="C#" AutoEventWireup="true" CodeFile="InitialPage.aspx.cs" Inherits="InitialPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modal {
position: fixed;
top: 0;
left: 0;
background-color: lightgray;
z-index: 99;
opacity: 0.8;
filter: alpha(opacity=80);
-moz-opacity: 0.8;
min-height: 100%;
width: 100%;
}
.loading {
font-family: Arial;
font-size: 10pt;
border: 5px dashed #f00;
width: 200px;
height: 100px;
display: none;
position: fixed;
background-color: White;
z-index: 999;
margin: 0 auto;
text-align: center;
padding-top: 35px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<div class="loading">
<div>
Loading. Please wait.<br />
<br />
<img src="loading.gif" alt="loading" />
</div>
</div>
Link To Another Page
<br /><br />
<asp:Button ID="btnPostBack" runat="server" OnClientClick="ShowProgress();" OnClick="btnPostBack_Click" Text="Do Long Process without Ajax" /><br /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button ID="btnAjax" runat="server" OnClick="btnPostBack_Click" Text="Do Long Process with Ajax" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="loading" style="display: table">
<div>
Processing. Please wait...<br />
<br />
<img src="loading.gif" alt="loading" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.css("vertical-align", "middle");
loading.css("display", "table-cell");
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
</script>
</form>
</body>
</html>

Master Page Contents aren't Same in All pages

I use Master Page in my Project.But Master Page contents are not same in all pages.In Home.aspx page it's margin is 0px and in other page isn't. Texts are Bold and Big Size in one page and Small in another Page. Why this occur?
My Master.master page Code :
<body style="margin:0px; text-align: left;">
<form id="form1" runat="server">
<div>
<div class="auto-style1" style="background-color: #3399FF; height: 42px;">
<h2>
<asp:Label ID="homeLabel" runat="server" Text="Home"></asp:Label>
</asp:Label>
<asp:Label ID="file_sharedLabel" runat="server" Text="Files Shared"></asp:Label>
<asp:Label ID="blogLabel" runat="server" Text="Blogs"></asp:Label>
</h2>
</div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
And Two picture of Home.aspx and Members.aspx are
What happens I don't Catch .
Again, it is hard to tell what is going on without the actual HTML from your child pages. However, judging from the picture, you are probably looking for a margin value on a an element between your <asp:ContentPlaceHolder> tags.
It looks like your second page is using a <table> of some sort.
Make sure your table has:
style="margin-top: 0px;"
Or
<table class="noTopMargin"> ...
<style>
.noTopMargin { margin-top: 0px; }
</style>
As for the font-size and font-weight being messed up, it is possible that your second page has a <style> declaration somewhere which is screwing it all up. Also make sure that your browser zoom is the same between both pages.

Show many images on asp.net page as thumbnails

I have saved images uploaded by user in one of my folders.In the sql server DB I just save the file-name of the image. For one item I have nearly 5-6 images. So I have an itemID as one of the column and imagename as one column and i have 1 2 3 4 5 in the table.
I need to display all these images in thumbnail format on a page. Like on craigslist. How do i proceed?
You can use javascript/jQuery image box to display a large image with small thumbnails.
Here are the two I know -
FancyBox (I'm currently using)
LightBox
Or You can use the following code -
Demo at jsfiddle
<style type="text/css">
.container img {
width: 100px;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function () {
$(".container img").mouseover(function () {
$("#<%= LargeImage.ClientID %>").attr("src", $(this).prop('src'));
}).mouseout(function () {
$("#<%= LargeImage.ClientID %>").attr("src",
"http://placehold.it/400x400&text=Image1");
});
});
</script>
<asp:Image ID="LargeImage" ImageUrl="http://placehold.it/400x400&text=Image1"
runat="server" />
<div class="container">
<asp:Image ID="Image1" ImageUrl="http://placehold.it/400x400&text=Image2"
runat="server" />
<asp:Image ID="Image2" ImageUrl="http://placehold.it/400x400&text=Image3"
runat="server" />
<asp:Image ID="Image3" ImageUrl="http://placehold.it/400x400&text=Image4"
runat="server" />
<asp:Image ID="Image4" ImageUrl="http://placehold.it/400x400&text=Image5"
runat="server" />
</div>

close Jquery Modal popup Datalist button click

i am running into a problem that i have a jquery modal popup in my usercontrol that i show on a click of a button and user selects something from datalist and then i returned some value on the parent user control in a hidden field all is fine till here but after the click on the select button i want the jquery modal to be closed also
here is some code of the div which i show in modal diaog
<asp:UpdatePanel ID="upDatagrabber" runat="server">
<ContentTemplate>
<table>
<tr>
<td>Select Category</td><td><asp:DropDownList ID="ddlTemplateCatagory"
runat="server" AutoPostBack="True"></asp:DropDownList></td>
</tr>
<tr>
<td colspan="2">
<table cellspacing="0" cellpadding="0" border="0" style="float:left;padding:5px;margin:5px;width:200px;display:block;">
<tbody>
<tr>
<asp:DataList ID="dlTemplates" runat="server" RepeatColumns="3"
RepeatDirection="Horizontal" onitemcommand="dlTemplates_ItemCommand">
<ItemTemplate>
<td style="border-right: gainsboro 1px solid; border-top: gainsboro 1px solid;
border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid;padding:5px;">
<table><tr><td>
<%# Eval("NewsletterName").ToString()%>
</td></tr>
<tr><td><asp:Button ID="btnSelectNL_Template" Text="Select" runat="server" CssClass="button" CommandArgument='<%# Eval("NewsletterId").ToString()%>' CommandName="Select"/></td></tr>
</table>
</td>
</ItemTemplate>
</asp:DataList>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</ContentTemplate>
and in the ItemCommandEvent I tried following
protected void dlTemplates_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int SelectedNewsletterId = int.Parse(e.CommandArgument.ToString());
if (NewsletterSelectedHandler!= null)
{
e.Item.Attributes.Add("onclick","jQuery('#mydialog').dialog('close');");
NewsletterSelectedHandler(SelectedNewsletterId);
}
}
}
EDIT
i shown the popup using this in my code behind
ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "change", "jQuery('#mydialog').dialog('open');closedialog = 1;jQuery('#mydialog').parent().appendTo(jQuery('form:aspnetForm'));", true);
popup shown successfully but i could not close it on the button click of datalist child button i tried code provided by tugburk i checked the error console also there is no error
code for close is as followd :
<script type="text/javascript">
$(document).ready(function(){
$('#ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_btnSelectNL_Template').click(function(){
$('#mydialog').dialog('close');
});
});
</script>
Any help would be appreciable
Many thanks in the Advance
use the following code;
$(document).ready(function(){
$('#<%= btnSelectNL_Template.ClientID %>').click(function(){
$('#id_of_your_dialog_element').dialog('close');
});
});
EDIT :
you are hardcoding your button id there;
ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_b‌​tnSelectNL_Template
DataList will produce multiple buttons if you have multiple records. add a class name to that button, and try to write a code against it
$('.MyButtonClass').click(function(){
$('#mydialog').dialog('close');
});

Horizontal orientation in Repeater control

I have a Repeater control used to display uploaded images.
How can I show the images in the repeater horizontally? How can i give the caption to the bottom of picture in this?
assuming you have some code like this:
<asp:repeater ...>
</asp:repeater>
just inject "<itemtemplate>" with some html code with the look and feel you want to. nothing special about showing horizontal or vertical it just depends on what html tags you use inside item templates.
If you don't especially need a Repeater to do this, you can use a DataList instead and set the RepeatDirection="Horizontal"
how to display horizontal line after each row
<asp:DataList ID="dlstmovie" runat="server" onitemcommand="dlstmovie_ItemCommand" RepeatColumns="5" ItemStyle-CssClass="item1" RepeatDirection="Horizontal" onitemdatabound="dlstmovie_ItemDataBound" >
<ItemTemplate>
<asp:LinkButton ID="lnkimg" runat="server" CommandName="m1" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"cinemaid")%>'>
<img src='<%=cinemaposter %><%#Eval("picturenm")%>' class="img" />
</asp:LinkButton>
<br />
<asp:LinkButton ID="lnkmovie" runat="server" CommandName="m1" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"cinemaid")%>' Text='<%#(Eval("cinemanm").ToString().Length>10)?(Eval("cinemanm").ToString().Substring(0,10))+"":Eval("cinemanm").ToString()%>' CssClass="blacktext"></asp:LinkButton>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="m1" CommandArgument ='<%#DataBinder.Eval(Container.DataItem,"cinemaid")%>' Font-Underline="false" CssClass="blacktext">...</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmptyData" Text="No Data To Display" runat="server" Visible="false" CssClass="blacktext">
</asp:Label>
</FooterTemplate>
</asp:DataList>
You can build your ItemTemplate like:
<ItemTemplate>
<div class="floating">
<img src='<%# /* Code to Eval your image src from datasource */ %>' alt='' />
<span><%# /* Code to Eval your image caption from datasource */ %></span>
</div>
</ItemTemplate>
where the .floating class of the div is:
.floating { float:left; overflow:hidden; }
.floating img { display: block; }
I usually put a div for clear after a sequence of floating element, to reset the state of box model.
<div style="clear:both;"></div>
Depends on what you are using to display, i.e. if your pictures are in a div put float:left; on it, or use the DataList.
Like #numenor said in this other answer, it's just a matter of what html you use. Here, an example of how to acomplish what you need using html tables.
<table width="<%= this.TotalWidth %>">
<tr>
<asp:Repeater runat="server" ID="rptABC" OnItemDataBound="rptABC_ItemDataBound">
<ItemTemplate>
<td class="itemWidth">
Your item goes here and will be
displayed horizontally as a column.
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>
Note that the width is handled with a server side property TotalWidth that calculates the total width needed based on, of course, the count of items repeater will display. Creating a CSS class to define the width of each item is also recomended to ensure proper layout.
protected string TotalWidth
{
get
{
//In this example this.Madibu.Materiales is the datasource for the Repeater,
//so this.Madibu.Materiales.Count is the column count for your table.
//75 must be equal to the width defined in CSS class 'itemWidth'
return (this.Madibu.Materiales.Count * 75).ToString() + "px";
}
}

Resources