Tuesday, 28 May 2013

Dynamic Ad Rotator in asp.net


adrotator-in-asp-net-using-database
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.
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
Untitled Page
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();
}
}

1 comment: