Menu control Databinding problem using StaticItemTemplate

A

Andrew Jocelyn

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.

<siteMapNode title="stuff" id="myid">

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
 
S

Steven Cheng[MSFT]

Hi Andrew,

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

** the <MenuItem> 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.

=======
<StaticItemTemplate>
<%# CallYourCustomFunctionHere( params....) %>
</StaticItemTemplate>
=========

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/default.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" <[email protected]>
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.

<siteMapNode title="stuff" id="myid">

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
 
A

Andrew Jocelyn

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?

<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
<StaticItemTemplate>
<%# GetMenuItem(Container.DataItem) %>
</StaticItemTemplate>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"
ShowStartingNode="false" />

Thanks
Andrew



Steven Cheng said:
Hi Andrew,

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

** the <MenuItem> 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.

=======
<StaticItemTemplate>
<%# CallYourCustomFunctionHere( params....) %>
</StaticItemTemplate>
=========

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/default.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" <[email protected]>
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.

<siteMapNode title="stuff" id="myid">

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
 
S

Steven Cheng[MSFT]

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" <[email protected]>
References: <#[email protected]>
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?

<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
<StaticItemTemplate>
<%# GetMenuItem(Container.DataItem) %>
</StaticItemTemplate>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"
ShowStartingNode="false" />

Thanks
Andrew



Steven Cheng said:
Hi Andrew,

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

** the <MenuItem> 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.

=======
<StaticItemTemplate>
<%# CallYourCustomFunctionHere( params....) %>
</StaticItemTemplate>
=========

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/default.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" <[email protected]>
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.

<siteMapNode title="stuff" id="myid">

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top