Reputation: 4727
I have two set of Images named as Div1 and Div2 that has to be called in the Slideshow. The condition is like that,
For the first Seven days, I want the first set of Div's of images to be shown in the slideshow, as soon as the seven days are completed the next set of Div's images should be shown. I know it is possible through the Timer Control. But I haven't used till now.
No code till now to share, as I have called the Images in slideshow from the table. Do let me know if you want anything else.
Please help. So that I can use it
Any help would be appreciable
My code for the slideshow is here:-
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultSQLConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT Name FROM tblImages", conn);
DataTable dt = new DataTable();
da.Fill(dt);
rptImages.DataSource = dt;
rptImages.DataBind();
Page.Header.DataBind();
}
aspx code:-
<div class="imgbanner-login" style="margin-bottom: 10px;">
<div class="img-login-ca">
<div class="index-img-banner">
<div id="slider" class="nivoSlider">
<asp:Repeater ID="rptImages" runat="server">
<ItemTemplate>
<li style="list-style: none;">
<img alt="" src='<%# Eval("Name") %>' />
</li>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
<div class="login">
<uc1:indexrightpanel runat="server" id="indexRightPanel" />
</div>
</div>
</div>
Also see the db strucutre:-
ID int Unchecked
Name nvarchar(MAX) Checked
[Order] int Checked
Name column consist the Image path
Upvotes: 0
Views: 695
Reputation: 1
I am not going to code anything, but a simple solution would be to have a startdate somewhere. You do a datediff for days and then a mod 14, anything below 7 is the first week, anything higher is the second week, do your select based on that condition
Upvotes: 0
Reputation: 11985
Here is a small database I've setup to demonstrate the idea of how to handle this requirement:
CREATE TABLE [dbo].[SetTable] (
[SetId] INT IDENTITY (1, 1) NOT NULL,
[SetName] VARCHAR (10) NOT NULL,
PRIMARY KEY CLUSTERED ([SetId] ASC)
);
Go
INSERT INTO SetTable values ('A'), ('B');
GO
CREATE TABLE [dbo].[SetShowLog] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[SetId] INT NOT NULL,
[LastShown] DATETIME DEFAULT (getdate()) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_SetShowLog_SetTable] FOREIGN KEY ([SetId]) REFERENCES [dbo].[SetTable] ([SetId])
);
Go
CREATE TABLE [dbo].[ImageTable] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[Name] VARCHAR (25) NULL,
[SetId] INT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_ImageTable_SetTable] FOREIGN KEY ([SetId]) REFERENCES [dbo].[SetTable] ([SetId])
);
Go
Insert into ImageTable ([Name], [SetId]) values
('image1.jpg', 1),
('image2.jpg', 1),
('image3.jpg', 2),
('image4.jpg', 2);
go
CREATE PROCEDURE [dbo].[GetImages]
AS
declare @logId int;
--get the last shown set
select @logid = IDENT_CURRENT('SetShowLog');
declare @setid int;
declare @lastShowDate datetime;
declare @now datetime;
set @now = GETDATE();
select
@setid = setid,
@lastShowDate = LastShown
from SetShowLog
where Id = @logId;
if @@ROWCOUNT = 0
begin
--this is first insert into the log table
insert into SetShowLog(SetId) values (1);
set @setid = 1; --we show set A as default
end
else
begin
if( DATEDIFF(dd, @lastShowDate, @now) > 7 ) --seven day check
begin
--change the set
select @setid = case @setid when 1 then 2
when 2 then 1 end;
--update log
insert into SetShowLog(SetId) values (@setid);
end
end --//end of @@rowcount check
select * from ImageTable where SetId = @setid;
RETURN 0
You can start off a new database file in visual studio and run the scripts to initialize the db...Check the stored proc GetImages
implementation.
This simply allows you to query images based on your requirement. You can re-use your code itself in the Timer postback, just making a call to the stored proc.
Upvotes: 2