[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Modifying image path in DataList template

Posted on 2007-11-29
6
Medium Priority
?
1,144 Views
Last Modified: 2008-02-01
Hi Experts !
I have a DataList that contains an Image as a template. The image contains the Images folder path... something like: Eval("Pictures","~/Images/{0}")
I'm going to use that DataList is a user control on different pages and I need to be able to change that image path to add sub folders to it: ex: ~/category1/Images{0} or ~/category2/Images{0}

I cannot find a way to access/change the ImageUrl property of the databound Image that's within the Datalist programatically. Does anyone know how to do it ?
Thank you.
<ItemTemplate>
        &nbsp;<asp:ImageButton ID="imgbImage" runat="server" Height="130px" ImageUrl='<%# Eval("Pictures","~/Images/{0}") %>'
            Width="130px" /><br />
        &nbsp;<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Pictures") %>'></asp:Label>
    </ItemTemplate>

Open in new window

0
Comment
Question by:techsuppoprt
[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
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:gocemi
ID: 20380431
Hi,
I suggeest taht you create public proerty of the control where user can specify the images path...

In the control inside

private string _imagesPath;
Piblic string ImagesPath
{
set{_imagesPath = value;}
}

And in the HTML
<dataListControl:CustomControl id=... runat=server ImagesPath="./PATHTOMYIMAGES" ... ></>

This way user will speciy from where datalist to fetch images

Hope this suits you
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 20383760
That's exactly the solution I was looking for.
Help me fix the HTML part please.. it doesn't work:

<asp:DataList ID="dtlAlbum" runat="server" BackColor="White" BorderColor="#336666"
    BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal"
    RepeatColumns="4">
    <DataListControl:CustomControl id="dtlAlbum" runat="server" ImagesPath="\Images"></>
    <FooterStyle BackColor="White" ForeColor="#333333" />
    <ItemStyle BackColor="White" ForeColor="#333333" />
    <SelectedItemStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
    <ItemTemplate>
        &nbsp;<asp:ImageButton ID="imgbImage" runat="server" Height="130px" ImageUrl='<%# Eval("Pictures","~/Images/{0}") %>'
            Width="130px" /><br />
        &nbsp;<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Pictures") %>'></asp:Label>
    </ItemTemplate>
</asp:DataList>

Open in new window

0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 20387324
Sorry, never mind the post above.
Doing public property is easy...Done.
The question is how do I make the DataList use that variable (ImagesPath ) as a source path to my Images folder?
Something like DataList.ItemTemplate.MyImage.ImageURL=ImagesPath;
What would be the correct way to do it ?
0
Independent Software Vendors: 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!

 
LVL 5

Expert Comment

by:gocemi
ID: 20389421
You'll need to implemet itemDataBound event
And check if you'r datalist contains elements that are using imags
ImageButton, image ....
quick method is
for each call
go trough all controls in the Item that is being data bounded
and see if it is of type image or imagebutton
    than change the data that is bound.

//recusrsion function that will check all controls in the item of one datalist
private string checkData(Control c)
{
foreach(Control innerControl in c.controls)
{
    if(innerControl.Controls.length > 0)
   {
     checkData(innerControl);
   }
  else
  {
    //this is a single control
     if(c is image or c is imageButton)
   {
   ///here change the path to the image...
   (c as image).ImageUrl = [path to the images] + (c as image).imageURL
    }
  }
}
}


Note: I might have som sintax errors or maybe even code misspelling but the logic is clear :)

when items are databound on datalist, go trough every control that is contained in the item and if it is a button or image (or any other control that hold pictures) than change the path to the image

Hope this helps

Regards,



private void onitemdatabound(object sender, eventArgs)
{
checkData( (sender as datalistItem);
}
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 20504096
Sorry for the delay... I"ve been trying to figure it out :)
I'm still struggling with this. Especially with this part:

   ///here change the path to the image...
   (c as image).ImageUrl = [path to the images] + (c as image).imageURL

How do I circle through images in the folder ?
0
 
LVL 5

Accepted Solution

by:
gocemi earned 1800 total points
ID: 20505765
You don't, i guess that image names will be sent from Database?
so just prefix the string with the property provided in the control
[path to the images] is public property that will be provided
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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

649 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