<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OleDb"%> <%@ Page Language="C#" Debug="true" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { AdRotatorDataTable(); AdRotatorDataTableRows(); } //*** AdRotator & DataTable ***// void AdRotatorDataTable() { OleDbConnection objConn; OleDbDataAdapter dtAdapter; DataTable dt = new DataTable(); String strConnString; strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("database/mydatabase.mdb")+""; objConn = new OleDbConnection(strConnString); objConn.Open(); String strSQL; strSQL = "SELECT * FROM banner"; dtAdapter = new OleDbDataAdapter(strSQL, objConn); dtAdapter.Fill(dt); dtAdapter = null; objConn.Close(); objConn = null; //*** AdRotator ***// this.myAdRotator1.DataSource = dt; this.myAdRotator1.ImageUrlField = "Logo"; this.myAdRotator1.AlternateTextField = "BannerName"; this.myAdRotator1.DataBind(); } //*** AdRotator & TableRows ***// void AdRotatorDataTableRows() { DataTable dt = new DataTable(); DataRow dr; //*** Column ***// dt.Columns.Add("BannerName"); dt.Columns.Add("Logo"); //*** Rows ***// dr = dt.NewRow(); dr["BannerName"] = "Banner 1"; dr["Logo"] = "images/banner-001.gif"; dt.Rows.Add(dr); //*** Rows ***// dr = dt.NewRow(); dr["BannerName"] = "Banner 2"; dr["Logo"] = "images/banner-002.gif"; dt.Rows.Add(dr); //*** ListBox ***// this.myAdRotator2.DataSource = dt; this.myAdRotator2.ImageUrlField = "Logo"; this.myAdRotator2.AlternateTextField = "BannerName"; this.myAdRotator2.DataBind(); } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - AdRotator & DataBind</title> </head> <body> <form id="form1" runat="server"> <asp:AdRotator id="myAdRotator1" runat="server"></asp:AdRotator><br /><br /> <asp:AdRotator id="myAdRotator2" runat="server"></asp:AdRotator><br /><br /> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท