473,748 Members | 7,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 3575

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

Similar topics

3
1731
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 little different. Can anyone write couple to lines of code for this? Moreover, If I want to insert any element at the mth place of nth col in list box of type Report. can I achieve it. Thanks in anticipation.
6
10718
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 display that? Thanks,
9
1532
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 Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
1
1928
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 knew how to filter paste message in WndProc. But I think disable menu is more sense. Thanks for any response.
0
746
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 Microsoft combo box on a form, then after a while, if I click on that to change properties or move it, then the focus jumps to one of my custom text boxes instead and it is impossible to select
1
5081
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 textbox(es) and the submit button showing until another option is selected. Also the data that's submitted is showing on the form page. Here's an example - I need the code below to do this: 1. I go to the page - I see a drop down box. 2. I...
7
3484
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 help..through php or javascript. ONe more thing..How can i perform the same function for more than one such kind of problem..I mean if there is any other place in the form where i have to display textbox on selecting a particular value.how can it be...
2
1419
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 other control which will allow users to enter their own text, then select some of it, and have the code read what has been selected? Thanks! Ethan
1
3479
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 display. but when i select Cheque on selection function work only for first row not working in other row. I am attaching the code snippet as well ... see if you can help ... <script language="javascript"> function handleOther(val){ if(val ==...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.