Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i am new to asp.net and i am creating a tourism website.In this website i have a slider which shows images of different places and this images are retrieved dynamically from database.Here i have used a repeater to create the slider as shown below

ASP.NET
<section class="slider">
        <div class="flexslider">
          <ul class="slides">
           
  	    		<asp:Repeater ID="rptImages" runat="server">
        <ItemTemplate>
            <li>
  	    	    <img src='<%# Eval("image") %>' alt="" />
                <div class="myCaption"><%# Eval("place") %></div>
  	    		</li>
        </ItemTemplate>
    </asp:Repeater>
  	    		
          </ul>
        </div>
      </section>


code behind
C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);

       //======= Select Query.
       string cmdText = "SELECT place,image FROM tourdescription  where id='" + id + "' ORDER BY descid";

       //====== Providning information to SQL command object about which query to
       //====== execute and from where to get database connection information.
       SqlCommand cmd = new SqlCommand(cmdText, con);

       //===== To check current state of the connection object. If it is closed open the connection
       //===== to execute the insert query.
       if (con.State == ConnectionState.Closed)
       {
           con.Open();
       }

       //===== Execute Query and bind data to ListView.
       rptImages.DataSource = cmd.ExecuteReader();
       rptImages.DataBind();



here slider has repeater with an image having an alt tag.i want to make this alt tag dynamic that if image slider displays image of new delhi then alt tag should be new delhi.if it displays agra then alt tag should be agra.Also it should help in bringing page first while searching agra in google image ie help in search engine optimisation.Can anyone tell me a way to do that.God bless you.Thank you in advance
Posted
Updated 16-Sep-14 8:03am
v2
Comments
ChauhanAjay 16-Sep-14 23:04pm    
if you are showing the name of the place in the div tag below the image, then set that value to the alt attribute of the image.
faizel s 17-Sep-14 13:26pm    
if i do that will it help in seo.

This is however a job of JavaScript to change the attribute of the HTML element upon some event. You can use jQuery for this if you want to shorten the code.

Upon loading the image, you can add this line

JavaScript
// if the image's source attribute is new delhi
if($('img').attr('src') == 'new_delhi.png') {
   // set the alt attribute to new delhi
   $('img').attr('alt', 'New Delhi');
   // otherwise
} else {
   // set to agra.
   $('img').attr('alt', 'Agra');
}


..you can add your own logic to this too. Otherway of doing this is to create a new child using C# in the serverside page and passing it down to the user using Ajax request. But that will be too broad. You can simply just change the source of the image and upon changing the source, change the alt attribute of the image too.
 
Share this answer
 
i trhink You conflick with the
C#
alt=""
and
C#
Title=""



where
C#
alt="No Image Found"
show if Image is unable to find or any error occur.
and
C#
Title="Delhi"
show the Image title on Mouse over on the image.
 
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