Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.aspnet.mobile
Re: objectlist control
Andy Wigley
5/10/2002 7:58:00 PM
1 Answer
PP
5/13/2002 11:35:00 PM
0
Thanks! That worked great!!
>-----Original Message-----
>You can't get at controls inside templates in the
OnItemDataBind event, since that creates the
ObjectListItem objects that contain the items to be
displayed in the list.
>The controls that are in the templates are created after
the data binding has completed. You have to find the
template container control for the item you want to
change, and inside that template container will be the
Label control you want to program.
>Within an ObjectList control, the templatecontainer is
the ObjectListItem controls, so if you walk through the
ObjectList's Controls collection, you're walking through
the collection of template containers. Then, for each
ObjectListItem, you can use FindControl to locate your
Label, and set properties of it.
>
>For example, If you have an ObjectList defined like this:
>
><mobile:Form id="Form1" runat="server">
> <mobile:ObjectList id=ObjectList1 runat="server"
> CommandStyle-StyleReference="subcommand" LabelStyle-
StyleReference="title"
> DataSource="<%# dataSet11 %>" DataMember="authors">
> <DeviceSpecific>
> <Choice
Xmlns="
http://schemas.microsoft.com/mobile/html32template...
> <ItemTemplate>
> <%# DataBinder.Eval(((ObjectListItem)
Container).DataItem, "au_lname") %>
> <br>
> <mobile:Label id="Label1"
runat="server">LabelInTemplate</mobile:Label>
> </ItemTemplate>
> </Choice>
> </DeviceSpecific>
> </mobile:ObjectList>
></mobile:Form>
>
>(I just used the pubs database in the SDK MSDE for the
data).
>Then to get at the Label1 in each ObjectListItem, one
technique you an use is to trap the OnPreRender event and
walk the collection of ObjectListItem objects in there -
by then the templated controls have been created, so you
can get at them:
>
>private void ObjectList1_PreRender(object sender,
System.EventArgs e)
>{
> //Walk through the controls in the ObjectList
> //This control is a ObjectListItem, which is also the
template container
> int itemcounter = 0;
> foreach (ObjectListItem item in ObjectList1.Controls)
> {
> System.Web.UI.MobileControls.Label label1 =
item.FindControl("Label1")
> as System.Web.UI.MobileControls.Label;
> if (label1 != null)
> {
> //test because label is in template - may not be
there for some clients
> label1.Text = "Set in code"
> }
> itemcounter++;
> }
>}
>
>Hope that gives you what you want.
>
>Regards
>- Andy Wigley
> MSPress: 'Building .NET Applications for Mobile Devices'
>
>
>
>"PP" <pganp@yahoo.com> wrote in message
news:1c6401c1f78e$66653510$9ae62ecf@tkmsftngxa02...
>> How can i access <mobile:label> control which is within
>> <itemtemplate> within <device specific> within an
object
>> list control? Thanks in advance.
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: objectlist control
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password