To create the database table for ads
Column name | Data type | Description |
Ads_ID | int | Primary key. This column can have any name. |
ImageUrl | varchar(length) | The relative or absolute URL of the image to display for the ad. |
NavigateUrl | varchar(length) | The target URL for the ad. If you do not provide a value, the ad is not a hyperlink. |
AlternateText | varchar(length) | The text displayed if the image cannot be found. In some browsers, the text is displayed as a ToolTip. Alternate text is also used for accessibility so that users who cannot see the graphic can hear its description read out loud. |
Keyword | nvarchar(length) | A category for the ad on which the page can filter. |
Impressions | int(4) | A number that indicates the likelihood of how often the ad is displayed. The larger the number, the more often the ad will be displayed. The total of all impressions values in the XML file may not exceed |
Code For Default.aspx Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Timer ID="SlideShowTimer" runat="server" Interval="5000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:AdRotator ID="AdRotator1" runat="server" Width="150" Height="150px" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SlideShowTimer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Code For Default.aspx.cs Page
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AdRotator1.DataSource = AdRotatorSunil();
AdRotator1.DataBind();
}
}
private DataTable AdRotatorSunil()
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("Server=SUNIL;Database=ExampleDB;Integrated Security=true");
SqlDataAdapter da = new SqlDataAdapter("select AlternateText,ImageUrl,NavigateUrl,Impressions from dbo.AdRotator", con);
da.Fill(dt);
return dt;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
AdRotator1.DataSource = AdRotatorSunil();
AdRotator1.DataBind();
//UpdatePanel1.Update();
}
}
0 comments:
Post a Comment