在一页中显示多个广告 [英] Showing multiple Advertisement in one page

查看:71
本文介绍了在一页中显示多个广告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数据库表[AddList]添加多个添加

AddId ImageUrl NavigateUrl展示说明
----------------------------------------------
1 ../1.jpg www .... 50 Addidas鞋子
2 ../2.jpg www .... 25诺基亚电话
3 ../3.jpg www .... 25 Fast Track手表
----------------------------------------------

我在datalist中添加了一个表,在lef列中,我添加了通过表[AddList]的数据源连接的AdRotator,在右侧,我想显示与特定AddId相关的描述.
这怎么可能?任何建议

但是每次我刷新页面时,与Add Id关联的内容在它们的位置都保持不变,并且Addrotator更改图像.

I need to add multiple add from the database table [AddList]

AddId ImageUrl NavigateUrl Impression Description
----------------------------------------------
1 ../1.jpg www.... 50 Addidas Shoes
2 ../2.jpg www.... 25 NOkia Phones
3 ../3.jpg www.... 25 Fast Track wrist watches
----------------------------------------------

i have added one table in datalist where in lef column i have added AdRotator connected by datasource of table [AddList] and on the right side i want to display the description associated with the particular AddId.
How is this possible? Any Suggestions

But every time i refresh the page the content associated with the Add Id remains constant at their locations and the the Addrotator changes the image.

推荐答案

请尝试一下... .
背后的代码::

公共局部类AdRotator:System.Web.UI.Page
{
int i = 0;
受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(!Page.IsPostBack)
{
DataSet ds = new DataSet();
字符串filePath = Server.MapPath(〜/XMLFile1.xml");
ds.ReadXml(filePath);
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
受保护的无效AdRotator1_AdCreated(对象发送者,AdCreatedEventArgs e)
{
AdRotator _adRotator =(AdRotator)sender;
DataList _dataList =(DataList)(_ adRotator.Parent.Parent);
标签lbldesc =(Label)_dataList .Items [i] .FindControl("Label1");
如果(lbldesc!= null)
lbldesc.Text = e.AdProperties ["AlternateText"].ToString();
标签lbldesc1 =(Label)_dataList .Items [i ++].FindControl("Label2");
如果(lbldesc1!= null)
lbldesc1.Text = e.AdProperties ["id"].ToString();
}
}

HTML代码:
< div>
< asp:DataList ID ="DataList1" runat ="server"
>
< HeaderTemplate>
< td>广告</td>
< td>说明</td>
</HeaderTemplate>

< ItemTemplate>

< td>
< asp:AdRotator ID ="AdRotator1" AdvertisementFile =〜/XMLFile1.xml" target ="_ self"
runat ="server" OnAdCreated ="AdRotator1_AdCreated"/>
</td>
< td>
< asp:Label ID ="Label1" runat ="server"></asp:Label> //显示说明
</td>
< td>
< asp:Label ID ="Label2" runat ="server"></asp:Label> //显示ID
</td>

</ItemTemplate>
</asp:DataList>
</div>希望它对您有用.
请让我知道,如果您有任何疑问.
谢谢,
曼尼莎·帕特尔(Manisha Patel)
Please try this....
Code behind::

public partial class AdRotator : System.Web.UI.Page
{
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataSet ds = new DataSet();
string filePath = Server.MapPath("~/XMLFile1.xml");
ds.ReadXml(filePath);
DataList1.DataSource = ds;
DataList1.DataBind();
}
}
protected void AdRotator1_AdCreated(object sender, AdCreatedEventArgs e)
{
AdRotator _adRotator = (AdRotator)sender;
DataList _dataList = (DataList)(_adRotator.Parent.Parent);
Label lbldesc = (Label)_dataList .Items[i].FindControl("Label1");
if (lbldesc != null)
lbldesc.Text = e.AdProperties["AlternateText"].ToString();
Label lbldesc1 = (Label)_dataList .Items[i++].FindControl("Label2");
if (lbldesc1 != null)
lbldesc1.Text = e.AdProperties["id"].ToString();
}
}

Html Code::
<div>
<asp:DataList ID="DataList1" runat="server"
>
<HeaderTemplate>
<td> Advertisment</td>
<td>Description</td>
</HeaderTemplate>

<ItemTemplate>

<td>
<asp:AdRotator ID="AdRotator1" AdvertisementFile="~/XMLFile1.xml" target="_self"
runat="server" OnAdCreated="AdRotator1_AdCreated" />
</td>
<td>
<asp:Label ID="Label1" runat="server" ></asp:Label> //Display Description
</td>
<td>
<asp:Label ID="Label2" runat="server" ></asp:Label> //display ID
</td>

</ItemTemplate>
</asp:DataList>
</div>I hope it will work for you.
Please let me know, If you have questions.
Thanks,
Manisha Patel


这篇关于在一页中显示多个广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆