<body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick1"> <asp:UpdatePanel ID="BannerPanel" runat="server" UpdateMode="Conditional"> <triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </triggers> <contenttemplate> <asp:AdRotator ID="AdRotator1" KeywordFilter="Asp.Net" runat="server" Height="55px" Width="100px" /> </contenttemplate> </div> </form> </body>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; public partial class ad_db : System.Web.UI.Page { SqlConnection con; public void getcon() { con = new SqlConnection("Data Source=joker-pc;Initial Catalog=mytest;Integrated Security=True"); con.Open(); } protected void Page_Load(object sender, EventArgs e) { getcon(); AdRotator1.DataSource = FetchAdsFromDB(); AdRotator1.DataBind(); } private DataTable FetchAdsFromDB() { getcon(); string sql = "select photo1 from pic"; SqlDataAdapter da = new SqlDataAdapter(sql,con ); DataTable dt = new DataTable(); da.Fill(dt); return dt; } protected void Timer1_Tick1(object sender, EventArgs e) { AdRotator1.DataSource = FetchAdsFromDB(); AdRotator1.DataBind(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)