Menu control Databinding problem using StaticItemTemplate

Menu control Databinding problem using StaticItemTemplate

am 14.01.2008 18:43:47 von J055

Hi

How do add custom attributes to a System.Web.UI.WebControls.MenuItem in a
StaticItemTemplate which I have saved in my
SiteMapDataSource file? e.g.



protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
string id = ((SiteMapNode)e.Item.DataItem)["id"];
if (id != null)
Trace.Write(id);
// add the attribute to the MenuItem
}

I can't see how you can do it with the Menu control. Do I have any other
options which are not too much work to implement?

Thanks
Andrew

RE: Menu control Databinding problem using StaticItemTemplate

am 15.01.2008 04:55:41 von stcheng

Hi Andrew,

As for adding custom attributes to ASP.NET 2.0 Menu control, it is limited
by the following things:

** the tag in Menu control is not sub controls, they're just
some property tag which is not directly constructed as a sub control at
runtime, there fore you can not add attributes into "MenuItem" class
instance

** so far the Menu control do not let you directly access the underlying
created MenuItem's actual control instance

One way for you to perform customization on the MenuItem(using template) is
add your data binding expression with custom functions. e.g.

=======

<%# CallYourCustomFunctionHere( params....) %>

=========

You can pass "Container" or "Container.DataItem" into your c ustom function
so as to determine the value to return in the custom function. How do you
think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx .

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Andrew Jocelyn"
>Subject: Menu control Databinding problem using StaticItemTemplate
>Date: Mon, 14 Jan 2008 17:43:47 -0000
>
>Hi
>
>How do add custom attributes to a System.Web.UI.WebControls.MenuItem in a
>StaticItemTemplate which I have saved in my
>SiteMapDataSource file? e.g.
>
>
>
>protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
>{
> string id = ((SiteMapNode)e.Item.DataItem)["id"];
> if (id != null)
> Trace.Write(id);
> // add the attribute to the MenuItem
>}
>
>I can't see how you can do it with the Menu control. Do I have any other
>options which are not too much work to implement?
>
>Thanks
>Andrew
>
>
>

Re: Menu control Databinding problem using StaticItemTemplate

am 15.01.2008 11:10:01 von J055

Hi Steven

When I pass a Container.DataItem it's always a MenuItem object. I cannot get
the underlying object from the SiteMapDataSource. Is this correct? I can't
get any additional information from the web.sitemap file. Any ideas?



<%# GetMenuItem(Container.DataItem) %>


ShowStartingNode="false" />

Thanks
Andrew



"Steven Cheng[MSFT]" wrote in message
news:yOLSIqyVIHA.4200@TK2MSFTNGHUB02.phx.gbl...
> Hi Andrew,
>
> As for adding custom attributes to ASP.NET 2.0 Menu control, it is
> limited
> by the following things:
>
> ** the tag in Menu control is not sub controls, they're just
> some property tag which is not directly constructed as a sub control at
> runtime, there fore you can not add attributes into "MenuItem" class
> instance
>
> ** so far the Menu control do not let you directly access the underlying
> created MenuItem's actual control instance
>
> One way for you to perform customization on the MenuItem(using template)
> is
> add your data binding expression with custom functions. e.g.
>
> =======
>
> <%# CallYourCustomFunctionHere( params....) %>
>

> =========
>
> You can pass "Container" or "Container.DataItem" into your c ustom
> function
> so as to determine the value to return in the custom function. How do you
> think?
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
>
> ==================================================
>
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
> ications.
>
>
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx .
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> --------------------
>>From: "Andrew Jocelyn"
>>Subject: Menu control Databinding problem using StaticItemTemplate
>>Date: Mon, 14 Jan 2008 17:43:47 -0000
>>
>>Hi
>>
>>How do add custom attributes to a System.Web.UI.WebControls.MenuItem in a
>>StaticItemTemplate which I have saved in my
>>SiteMapDataSource file? e.g.
>>
>>
>>
>>protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
>>{
>> string id = ((SiteMapNode)e.Item.DataItem)["id"];
>> if (id != null)
>> Trace.Write(id);
>> // add the attribute to the MenuItem
>>}
>>
>>I can't see how you can do it with the Menu control. Do I have any other
>>options which are not too much work to implement?
>>
>>Thanks
>>Andrew
>>
>>
>>
>

Re: Menu control Databinding problem using StaticItemTemplate

am 17.01.2008 09:33:28 von stcheng

Hi Andrew,

Yes, it's a pity that the MenuItem class is a sealed class that can not
extend(I previously handled some issue about TreeView control and its
TreeNode class can be derived).

Currently, based on my research, one means to provide additional data would
be using the "Value" property of the MenuItem, do you think it posible that
you bind all the information together (through some separator char) into
the single "Value" property. And in your template, you can use some helper
function to parse those mutiple properties out?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: "Andrew Jocelyn"
>References: <#cwhFUtVIHA.4140@TK2MSFTNGP04.phx.gbl>

>Subject: Re: Menu control Databinding problem using StaticItemTemplate
>Date: Tue, 15 Jan 2008 10:10:01 -0000
>
>Hi Steven
>
>When I pass a Container.DataItem it's always a MenuItem object. I cannot
get
>the underlying object from the SiteMapDataSource. Is this correct? I can't
>get any additional information from the web.sitemap file. Any ideas?
>
>
>
><%# GetMenuItem(Container.DataItem) %>
>

>

> >ShowStartingNode="false" />
>
>Thanks
>Andrew
>
>
>
>"Steven Cheng[MSFT]" wrote in message
>news:yOLSIqyVIHA.4200@TK2MSFTNGHUB02.phx.gbl...
>> Hi Andrew,
>>
>> As for adding custom attributes to ASP.NET 2.0 Menu control, it is
>> limited
>> by the following things:
>>
>> ** the tag in Menu control is not sub controls, they're just
>> some property tag which is not directly constructed as a sub control at
>> runtime, there fore you can not add attributes into "MenuItem" class
>> instance
>>
>> ** so far the Menu control do not let you directly access the underlying
>> created MenuItem's actual control instance
>>
>> One way for you to perform customization on the MenuItem(using template)
>> is
>> add your data binding expression with custom functions. e.g.
>>
>> =======
>>
>> <%# CallYourCustomFunctionHere( params....) %>
>>

>> =========
>>
>> You can pass "Container" or "Container.DataItem" into your c ustom
>> function
>> so as to determine the value to return in the custom function. How do you
>> think?
>>
>> Sincerely,
>>
>> Steven Cheng
>>
>> Microsoft MSDN Online Support Lead
>>
>>
>>
>> ==================================================
>>
>> Get notification to my posts through email? Please refer to
>>
http://msdn.microsoft.com/subscriptions/managednewsgroups/de fault.aspx#notif
>> ications.
>>
>>
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/default.aspx .
>>
>> ==================================================
>>
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> --------------------
>>>From: "Andrew Jocelyn"
>>>Subject: Menu control Databinding problem using StaticItemTemplate
>>>Date: Mon, 14 Jan 2008 17:43:47 -0000
>>>
>>>Hi
>>>
>>>How do add custom attributes to a System.Web.UI.WebControls.MenuItem in a
>>>StaticItemTemplate which I have saved in my
>>>SiteMapDataSource file? e.g.
>>>
>>>
>>>
>>>protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
>>>{
>>> string id = ((SiteMapNode)e.Item.DataItem)["id"];
>>> if (id != null)
>>> Trace.Write(id);
>>> // add the attribute to the MenuItem
>>>}
>>>
>>>I can't see how you can do it with the Menu control. Do I have any other
>>>options which are not too much work to implement?
>>>
>>>Thanks
>>>Andrew
>>>
>>>
>>>
>>
>
>
>