?
Solved

Display data in datalist

Posted on 2006-07-10
10
Medium Priority
?
382 Views
Last Modified: 2011-10-03
Hi All!
i have a datalist as below
<asp:datalist id="repPhotoG" runat="server" RepeatDirection="Horizontal">
  <ItemTemplate>

     <a onclick="return enlarge('ThuVienHinhAnh/large_25163.gif',event)"><img      runat=server src='<%# DataBinder.Eval(Container.DataItem, "HinhAnh") %>'  title='<%# DataBinder.Eval(Container.DataItem, "HinhAnh") %>' width="69" height="95" style="cursor:pointer"></a>

</ItemTemplate>
</asp:datalist>
Now I want Replace "ThuVienHinhAnh/large_25163.gif" by <%# DataBinder.Eval(Container.DataItem, "HinhAnh") %> How To?, Thanks
Regards,
0
Comment
Question by:duynnh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 9

Expert Comment

by:valkyrie_nc
ID: 17073537
Best way I see is to add runat="server" to the <a> tag, and then add the onclick event on itemdatabound:

<a id="namedLink" runat="server"><img ... /></a>

In ItemDataBound event:

pull the value of HinhAnh any way you like (maybe store the value in an invisible label), and then

namedLink.Attributes.Add("onclick","return enlarge(" + HinhAnh + ",event);");


hth

valkyrie_nc
0
 

Author Comment

by:duynnh
ID: 17073591
Hi valkyrie_nc!
I didn't find itemdatabound  event of <a> tag
0
 
LVL 9

Expert Comment

by:valkyrie_nc
ID: 17073671
Since you're using a datalist, you would create an ItemDataBound event, tie it to your DataList, and use it.  You might want to turn the <a> tag into an <asp:HyperLink> tag to make it easier to hunt down using FindControl (apologies if you're a VB.Net person; I'm not that great at translating):

<asp:DataList ID="repPhotoG" runat="server" RepeatDirection="Horizontal" OnItemDataBound="repPhotoG_ItemDataBound">...</asp:DataList>

In code-behind:

protected void repPhotoG_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
   if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item || e.Item.ItemType == System.Web.UI.WebControls.ListItemType.AlternatingItem)
   {
      HyperLink namedLink = e.Item.FindControl("namedLink") as HyperLink;
      Label hinhLbl = e.Item.FindControl("hinhLbl") as Label; // if you used a label to store the data for code-behind retrieval; just one way to do it
      string HinhAnh = hinhLbl.Text;
      namedLink.Attributes.Add("onclick","return enlarge(" + HinhAnh + "),event);");
   }
}

Regardless, since you're mixing a DataItem value (HinhAnh) with non-databinder info (return enlarge(value,event)), you'll need to either do it from code-behind, or alternatively if you're using SQL, you can return the value of HinhAnh to have it include "return enlarge(value,event)" as part of its value, and use that without restoring to code-behind.

hth

valkyrie_nc
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:duynnh
ID: 17073746
Hi valkyrie_nc!
I don't use HyperLink, i just use <img> tag
0
 
LVL 9

Expert Comment

by:valkyrie_nc
ID: 17073761
You'd use HyperLink in place of the <a> tag; the <img> tag is fine:

<asp:HyperLink ID="namedLink" runat="server"><img src="file.jpg" ... /></asp:HyperLink>

Make more sense, or less?  I'm trying not to drown you in stuff you already know. :)

hth

valkyrie_nc
0
 

Author Comment

by:duynnh
ID: 17073833
Hi valkyrie_nc!
I have solved my problem as below:
Private Sub repPhotoG_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles repPhotoG.ItemDataBound
     
        Dim img As System.Web.UI.HtmlControls.HtmlImage = e.Item.FindControl("iPhoto")
        img.Attributes.Add("onclick", "return enlarge('" + img.Src + "',event);")


     
    End Sub
0
 
LVL 9

Expert Comment

by:valkyrie_nc
ID: 17073840
Beautiful!  
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 17356288
PAQ / No Refund
ee ai construct, community support moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question