473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

C#-WEB: getting selected menuitem to display in textbox

Just to start off, I am writing a web application using C#. I have a Menu which is binded to an XML datasource. There are three menu items each with submenus and a textbox where I want to display the value of the selected menu item. Heres the XML datasource that I am using:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Home>
  3.   <Menu text="Patient" description=" ">
  4.     <SubMenu text="First Name" description="firstName"></SubMenu>
  5.     <SubMenu text="Last Name" description="lastName"></SubMenu>
  6.     <SubMenu text="Birth Date" description="birthDate"></SubMenu>
  7.     <SubMenu text="Gender" description="gender"></SubMenu>
  8.     <SubMenu text="SSN" description="ssn"></SubMenu>
  9.   </Menu>
  10.   <Menu text="Contact"  description=" ">
  11.     <SubMenu text="Address" description="ptAddress"></SubMenu>
  12.     <SubMenu text="City" description="city"></SubMenu>
  13.     <SubMenu text="State" description="ptState"></SubMenu>
  14.     <SubMenu text="Zip" description="addPhone"></SubMenu>
  15.     <SubMenu text="Home Phone" description="dayPhone"></SubMenu>
  16.     <SubMenu text="Day Phone" description="dayPhone"></SubMenu>
  17.     <SubMenu text="Mobile Phone" description="mobilePhone"></SubMenu>
  18.     <SubMenu text="Email" description="email"></SubMenu>
  19.   </Menu>
  20.   <Menu text="Exam Info" description=" ">
  21.     <SubMenu text="Last Exam" description="lastExam"></SubMenu>
  22.     <SubMenu text="Is former patient(yes/no)" description="isFormPatient"></SubMenu>
  23.   </Menu>
  24. </Home>
  25.  
Now when I select any of the submenu values under the "Patient" menu, the value of the selected menuitem is displayed properly. If I click on any of the other submenu items under "Contact" or "Exam Info", nothing gets displayed in the textbox.

Here is my HTML code and C# code:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.         <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml"></asp:XmlDataSource>
  13.         <br />
  14.     <asp:Menu ID="Menu1" runat="server" DataSourceID="XmlDataSource1" MaximumDynamicDisplayLevels="4" DynamicHorizontalOffset="1" DynamicVerticalOffset="1" OnMenuItemClick="Menu1_MenuItemClick">
  15.               <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
  16.               <DynamicHoverStyle BackColor="#990000" Font-Bold="False" 
  17.                 ForeColor="White" />
  18.               <DynamicMenuStyle BackColor="#FFFBD6" />
  19.                <StaticSelectedStyle BackColor="#FFCC66" />
  20.               <DynamicSelectedStyle BackColor="#FFCC66" />
  21.               <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
  22.             <DataBindings>
  23.                 <asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="description" />
  24.                 <asp:MenuItemBinding DataMember="SubMenu" TextField="text" ValueField="description" />
  25.             </DataBindings>
  26.               <StaticHoverStyle BackColor="#990000" Font-Bold="False" ForeColor="White" />
  27.         </asp:Menu>
  28.         <br />
  29.         <br />
  30.         <asp:TextBox ID="TextBox1" runat="server" Width="520px"></asp:TextBox></div>
  31.     </form>
  32. </body>
  33. </html>
  34.  
My C# code:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10.  
  11. public partial class _Default : System.Web.UI.Page 
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.  
  16.     }
  17.     protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
  18.     {
  19.         TextBox1.Text += Menu1.SelectedItem.Value;
  20.     }
  21. }
  22.  
Also, if i change my c# code to
Expand|Select|Wrap|Line Numbers
  1. protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
  2. {
  3.       TextBox1.Text += Menu1.SelectedItem.Text;
  4. }
  5.  
Whenever I click on "Contact" or "Exam Info", I get the value of "Patient"
Any ideas or suggestions?
Thanks in advanced.
Jan 11 '08 #1
0 3540

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Vijay | last post by:
Hi, Iam new to VC++6.0. I want to display selected item of the ListBox in a MessageBox. I know for experience ppl it must be a kids play but for me who had worked in C# and VB, it seems to be...
6
by: tfs | last post by:
I am trying to display some data that is about 200 characters long and I was trying to display it on the screen in a textbox <asp:textbox /> But I don't want any borders. How would I...
9
by: Patrick Olurotimi Ige | last post by:
On PageLoad i did -: name.ID = Request.ServerVariables; on asp.net page i have <asp:textbox runat="server" ID="name"/> But when i load my page the textbox is blank Any ideas? *** Sent via...
1
by: Rulin Hong | last post by:
Menu "Paste" in textbox control's built-in contextmenu will be automaticaly enabled while having text in clipboard. I want to disable the menu when text in clipboard didn't meet my format. I...
0
by: Mark | last post by:
Hi Using vb.net 2005, got rather an annoying problem in windows forms My app uses a custom textbox control that I made myself - that all works fine However, if I place the standard...
1
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the...
7
by: TechnoAtif | last post by:
Hi..There is again a similar problem..Now i;ve got the option values of list?menu box to show the textbox. If the option value of list is yes then the textbox is to be displayed . Can anyone...
2
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I am using C#.net 2.0 to write a web application. I would like to be able to programmatically detect what text has been selected in a textbox control. Is this possible? If not, is there some...
1
by: nawedita | last post by:
Hi I am facing a problem with my code .... this is what I am doing ... I am running this dropdown in while loop...and i want when i select Cheque then display textbox otherwise textbox not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.