Answered by:
Mobile Web Form Item templates

Question
-
User-1137255554 posted
Hi,
I am newbie in using the Mobile Web Forms. I have placed <mobile:Image> in the ItemTemplate of a <mobile:ObjectList> ; now what i want to do is display images in this Image control from a collection object which holds the image URLs in string format.
<
mobile:ObjectList id="ImageList" runat="server" OnItemDataBind="OnIDB" >I have tried using the OnItemDataBind event of the Object List where I can bind the src Image URL to the image control.But when i try to find the control and set the ImageURL using the code below ::
System.Web.UI.MobileControls.Image Img = new System.Web.UI.MobileControls.Image();
Img = (System.Web.UI.MobileControls.Image) e.ListItem.FindControl("Image1");Img.ImageUrl = ImageCollection[i].ToString(); // here ImageCollection is an ArrayList
it returns null;
How do I set the source to the Image control dynamically using the collection [ Arraylist]
I would appreciate if someone can send me some source code or samples on how to do this .
Thanks in Advance.
CJ.
Tuesday, April 24, 2007 11:50 AM
Answers
-
User731069546 posted
Not exactly what you have but when using Mobile:Link control in the item template of the ObjectList control, I do the following:
In Page_Load event, I set the ObjectList to my datasource (an arrayList) and do the databinding.
In PreRender event of the ObjectList
Protected
Sub ObjectList1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ObjectList1.PreRender Dim item As MobileControls.ObjectListItem For Each item In ObjectList1.Items Dim link As System.Web.UI.MobileControls.Linklink = item.FindControl(
"Link1") If Not link Is Nothing Thenlink.NavigateUrl = "Set to whatever you want"
End If Next End SubThis seems to work fine for me.
I just wish all this was clearly explained somewhere. Every article you read only does micky mouse stuff.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 26, 2007 12:05 PM
All replies
-
User731069546 posted
Not exactly what you have but when using Mobile:Link control in the item template of the ObjectList control, I do the following:
In Page_Load event, I set the ObjectList to my datasource (an arrayList) and do the databinding.
In PreRender event of the ObjectList
Protected
Sub ObjectList1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ObjectList1.PreRender Dim item As MobileControls.ObjectListItem For Each item In ObjectList1.Items Dim link As System.Web.UI.MobileControls.Linklink = item.FindControl(
"Link1") If Not link Is Nothing Thenlink.NavigateUrl = "Set to whatever you want"
End If Next End SubThis seems to work fine for me.
I just wish all this was clearly explained somewhere. Every article you read only does micky mouse stuff.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 26, 2007 12:05 PM -
User-1137255554 posted
Hi Bobbyz,
Thanks for the idea.The pre-render works good.
U r very right there is very little info available on these concepts on the net.
I am pasting the C# code below; lets see if it does good to someone else too.:)
C# Code :
foreach (ObjectListItem item in ObjectList.Items)
{
i += 1;
System.Web.UI.MobileControls.Image img = (System.Web.UI.MobileControls.Image)item.FindControl("Image1");
if (img != null)
img.ImageUrl = ImageList[i].ToString();
img.NavigateUrl =
"Page2.aspx";}
Friday, April 27, 2007 12:09 PM -
User731069546 posted
Good that the solution worked for you. You should mark the post as "answered" so others can check if they looking for something similar.Monday, April 30, 2007 12:22 PM -
User-1113132963 posted
Hi CJRyun, In your Page_Load event, how you set the ObjectList to the datasource (an arrayList) and do the databinding. I have try your code, and i am confused about it. Can you show me the code on how to do it. Thank in advance.Wednesday, August 8, 2007 11:53 PM -
User-1137255554 posted
Hey inesense,
... below is the code for the page_load ...
ImageList is the Obejct List
ImageList.DataSource = null; ArrayList ImageCollection = new ArrayList();ImageCollection = DA.GetImages();
ImageList.DataSource = ImageCollection;ImageList.DataBind();
u might have already got this done ... but if u didnt this is for you !
CJ
Wednesday, September 19, 2007 4:50 AM