Click here to Skip to main content
15,920,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 5-Apr-11 3:54am
v2

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900