0

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

Nad
  • 4,605
  • 11
  • 71
  • 160
  • Here is the documentation:http://msdn.microsoft.com/en-us/library/bb398865(v=vs.100).aspx. Read it try to do something for your case and come back. – mybirthname Dec 15 '14 at 11:59
  • @mybirthname: Thanks for the reference, i will try that for sure :) – Nad Dec 15 '14 at 12:02
  • 7 days!!! as in the browser is expected to stay open that long?! – deostroll Dec 15 '14 at 12:31
  • @deostroll: The client's requirement s for the 7 days, after that the next set of images. Is it possible,please help. The browser part is not their issue. We just have to make it run for the 7 days and after that next set of images – Nad Dec 15 '14 at 12:41
  • Is the requirement such that the browser program has to be open 24 hours on all 7 days? – deostroll Dec 15 '14 at 13:01
  • No just from the start it has to be their in the slideshow, whether the browser is open or closed. Just 7 days from the start.That's it – Nad Dec 15 '14 at 13:04
  • This has to be **aptly** handled taking the aide of a database technology. But, what do you mean by _start_ here? Do you mean for every new user regardless of when he logs in he should see those specific images for 7 days? Or is it simply the time the web page is put to production on the server? – deostroll Dec 15 '14 at 13:14
  • @deostroll: You are not getting what I am saying. There is not such login things here. I want just the first set of the images to be displayed for 7 days. Here start means when it is uploaded from the database. I m sorry if I am rude. – Nad Dec 15 '14 at 13:16
  • I don't mean to sound rude either...When you store images to the db, you store it along with the server timestamp. Then in the asp.net page, query all the data (image + timestamp) and determine, through some server side computation of course, whether the image can be aired or not... – deostroll Dec 15 '14 at 13:22
  • OK, till now I have called the images from the table into the slideshow, Can you tell me the query ? Also, do I need to use the Timer control for that to implement. Please provide some code related stuff so it would be easy for us to recognize. If you want my code what I tried, i will show you. Thanks – Nad Dec 15 '14 at 13:24
  • Please do. Your db schema + asp.net code... – deostroll Dec 15 '14 at 13:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66927/discussion-between-nadeem-khan-and-deostroll). – Nad Dec 15 '14 at 13:32

2 Answers2

2

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.

deostroll
  • 11,661
  • 21
  • 90
  • 161
  • Yes. On the timer fired event, you need to write the code you have written in page load...only the part that binds the repeater. And I guess you can set a very high interval for it too... – deostroll Dec 16 '14 at 06:38
  • Your SelectCommand should be made to query results from the stored proc, instead of plain sql query... – deostroll Dec 16 '14 at 07:54
  • you mean to say the rest of my code is fine, just need to add the procedure like below:- `SqlDataAdapter da = new SqlDataAdapter("GetImages", conn); ` – Nad Dec 16 '14 at 07:56
  • 1
    Take a look at [this](http://stackoverflow.com/q/3528305/145682) if you are unsure how to use SelectCommand with a stored proc – deostroll Dec 16 '14 at 08:08
  • Ok sure, will implement and let you know. Thanks :) – Nad Dec 16 '14 at 08:10
  • @destroll: Just wanted to confirm one thing, how the timer is calculating the time ? I implemented that and it is working properly – Nad Dec 16 '14 at 10:04
  • http://msdn.microsoft.com/en-us/library/system.web.ui.timer.interval(v=vs.100).aspx ... it injects a settimeout js into the page. When timeout elapses, it causes the html form to postback...this is trapped as a Tick event on the control (server side). I hope this is enough from my side. – deostroll Dec 16 '14 at 10:53
  • thanks a lot dude, it is working as a charm. +1 for the stored procedure. – Nad Dec 17 '14 at 17:32
  • @deostroll : Can i get link on each image that we have given in database – Nad Dec 18 '14 at 13:46
  • 1
    What problem have you faced with trying that...? – deostroll Dec 18 '14 at 14:23
  • @deostroll: I just want that every image in the slideshow should be linked to some pages of the site.for ex:- `Img1` shd be linked to `www.home/abc.aspx`. Can I give the link ? – Nad Dec 18 '14 at 16:23
  • @deostroll: I haven't tried, I think adding one more column in the table which has links to the respective images would be great. – Nad Dec 18 '14 at 17:31
  • You are almost there...what is stopping you? The SO community would not approve of what I've done so far, because they manically frown upon newbies and their non-methodical approach to posting questions out here like its their homework they want help with...they rightly do so because "this" is exactly what detests veteran users of this site. – deostroll Dec 18 '14 at 18:40
  • @deostroll: I agree with you and I appreciate your efforts were speechless on what you did. Anyways, I will try and let you know. – Nad Dec 19 '14 at 05:56
  • @deostroll: Hi, I tried with adding one more column for URL click in the table.And added the code like this :-`
  • ` but it was not working – Nad Dec 22 '14 at 11:57
  • You'll have to study the rendered output (view source) to figure out what is going on...if that still doesn't help, I suggest you post another question. – deostroll Dec 22 '14 at 12:14
  • I inspected it in firebug and was getting like this, `
  • `
    – Nad Dec 22 '14 at 13:40