Obtaining advertisements for the AdRotator

Sheldon Penner 1 Reputation point
2022-06-26T12:29:54.403+00:00

I would like to include a column of advertisements on my asp.net web application using the AdRotator control. I would like to have my app send a list of key words to an advertising source and for the source to then return a collection of relevant advertisements. Is such a service available?

Community Center | Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,101 Reputation points
    2022-06-27T06:49:59.063+00:00

    Hi @Sheldon Penner ,
    Assume you have a xml file and then you could use linq to select the value. Finally,you only need to rebind it to the AdRotator.Just like this:

    <asp:AdRotator ID="AdRotator1" runat="server"/>  
                Key word:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
                <asp:Button ID="Button1" runat="server" Text="Button"  O nClick="Button1_Click"/>  
    

    Code behind:

    protected void Button1_Cl ick(object sender, EventArgs e)  
            {  
                var x = TextBox1.Text;  
                DataTable dt = new DataTable();  
                dt.Columns.Add("ImageUrl");  
                dt.Columns.Add("NavigateUrl");  
                dt.Columns.Add("AlternateText");  
                dt.Columns.Add("Impressions");  
                dt.Columns.Add("Keyword");  
                XElement xelement = XElement.Load(Server.MapPath("~/XMLFile2.xml"));  
                var keyword = from kw in xelement.Descendants("Ad")  
                          w here (string)kw.Element("Keyword") == x  
                          select new {  
                              ImageUrl = kw.Element("ImageUrl").Value,  
                              NavigateUrl = kw.Element("NavigateUrl").Value,  
                              AlternateText = kw.Element("AlternateText").Value,  
                              Impressions = kw.Element("Impressions").Value,  
                              Keyword = kw.Element("Keyword").Value  
                          };  
    

    xml file:

    <?xml version="1.0" encoding="utf-8" ?>  
    <Advertisements>  
      <Ad>  
        <ImageUrl>rose1.jpg</ImageUrl>  
        <NavigateUrl>http://www.1800flowers.com</NavigateUrl>  
        <AlternateText>  
          Order flowers, roses, gifts and more  
        </AlternateText>  
        <Impressions>20</Impressions>  
        <Keyword>flowers</Keyword>  
      </Ad>  
      
      <Ad>  
        <ImageUrl>rose2.jpg</ImageUrl>  
        <NavigateUrl>http://www.babybouquets.com.au</NavigateUrl>  
        <AlternateText>Order roses and flowers</AlternateText>  
        <Impressions>20</Impressions>  
        <Keyword>gifts</Keyword>  
      </Ad>  
      
      <Ad>  
        <ImageUrl>rose3.jpg</ImageUrl>  
        <NavigateUrl>http://www.flowers2moscow.com</NavigateUrl>  
        <AlternateText>Send flowers to Russia</AlternateText>  
        <Impressions>20</Impressions>  
        <Keyword>russia</Keyword>  
      </Ad>  
      
      <Ad>  
        <ImageUrl>rose4.jpg</ImageUrl>  
        <NavigateUrl>http://www.edibleblooms.com</NavigateUrl>  
        <AlternateText>Edible Blooms</AlternateText>  
        <Impressions>20</Impressions>  
        <Keyword>gifts</Keyword>  
      </Ad>  
    </Advertisements>  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.