updating label text based on selected item in a DropDownList (LINQ, VB.NET)

Hello experts,

Quick question for you: I'm writing a form that loads an XML file as an XDocument and populates the items in a DropDownList based on a field in the XML structure.

What I would like to do is change the text on certain labels in the form based on what is selected in the DropDownList. I've got the first part of this down, but am having trouble getting the label text changed. Any assistance you can give me is appreciated.

Here's the XML file:



  And here's the code I'm using:


Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim MyKBS = XDocument.Load("C:\6000.xml")

Dim XmlProc1 = From proc In MyKBS...<SubErrorCode> _
Where proc.<Number>.Value Is DropDownList1.SelectedItem.ToString _
Select proc

For Each item In XmlProc1
lblErrMsg.Text = item.<ErrMsg>.Value.ToString
lblWIH.Text = item.<WIH>.Value.ToString
lblHTF.Text = item.<HTF>.Value.ToString
lblDI.Text = item.<DI>.Value.ToString

End Sub


TIA for your help.


12/10/2008 2:32:13 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 2

can u plz send me the code written in page load


12/11/2008 5:32:16 AM

As a solution, I wrote a demo for your reference,


<%@ Page Language="C#" %>

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace=" System.Xml.Linq" %>
<%@ Import Namespace=" System.Linq" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    class Patient
        public string EMail { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    class PatietList : List<Patient>
        public void Load(string xmlFile)
            XDocument doc = XDocument.Load(xmlFile);

            var query = from xElem in doc.Descendants("Patient")
                        select new Patient
                            EMail = xElem.Attribute("EMail").Value,
                            FirstName = xElem.Element("FirstName").Value,
                            LastName = xElem.Element("LastName").Value,

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            PatietList patietList = new PatietList();
            ddlDemo.DataSource = patietList;
            ddlDemo.DataTextField = "FirstName";
            ddlDemo.DataValueField = "EMail";

    protected void ddlDemo_SelectedIndexChanged(object sender, EventArgs e)
        lblMsg.Text = ddlDemo.SelectedItem.Text;

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
        <asp:DropDownList ID="ddlDemo" runat="server" AutoPostBack="True" 
        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>


  <Patient EMail="LeBron@James.com">
  <Patient EMail="Kobe@Bryant.com">
  <Patient EMail="Allen@Iverson.com">

Note: I use the refer the following article to get the XML data soruce,


By the way, it seems that you are familiar with VB, please use the following tool to convert the C# to VB if you are not familiar with C#,



Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
12/12/2008 6:22:11 AM

Similar Artilces:

I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateComm...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Text out of a formview control (label, textbox, dropdownlist) in vb.net
How would I get the text or selectedvalue out of a from view control into the subject of an email? Here is my code Dim message As New MailMessage Dim server As New SmtpClient("mail.domain.com") Dim fromAddress As New MailAddress("Program@domain.com") message.Subject = (Label(frmNewQCI.FindControl("P1CategoryLabel").Text)) message.Body = "New QCI Created" message.To.Add("me@domain.com") message.From = fromAddress server.Send(message)   It is underlining Label and saying   'Label' is a type and cannot be used as an expression.  It's also underlining the rest an...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

VB .net Web Form will not get contents of Text Box
I have created a web form with text boxes that are bound to a DataSet/DataView.  I have created button to navigate up and down the recordset.  That all works fine. I need to have the ability to edit/add text in any of the boxes and then when clicking "Save" button, it would build an UPDATE query to send to the database. When the Save button is clicked, I have coded to DIM a string var (strSQL) to use to build the SQL command.  For some reason, it will only get the text from a text box if the data was pulled the database.  If I add/edit data, then the SQL command will ha...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Converting Web Site from Vb.Net 2003 to Vb.Net 2005
I have a web site in vb.net 2003 that I what to convert to vb.net 2005. I open my web site in the visual studio 2005 by Local IIS option. I follow the steps of the visual studio conversion wizard.In the conversion report I received the following warning 'Referencepath' settings have not been converted.  Can anyone tell what I have to do to make this warning disappear? Best regards,Sérgio 'Referencepath'  is a property you can set with with VS2003 project file, sothat when ever you to do Add reference this path is serached for class libraries.  We do not  have that ...

using a button (in vb.net) to launch a new page based on dropdownlist selection
Hi, I am creating a page for my students for my personal website. I teach piano, and I would like to set up a site where my students can see assignments/personal grades based on their login. Once they login, my site will launch and on the homepage, there is a dropdownlist of three items representing level of study: Beginner, Intermediate and Advanced. If the student selects "Beginner" from the dropdownlist, they click the "submit" button and the "Beginner" page will launch listing items unique to them (the unique items are based on their individual log...

Can a .NET web based intranet application call a windows based .NET application?
   Is it possibly to have an asp.net 2.0 application call/invoke a windows desktop application written in .NET 2.0? We have a .NET 1.0 windows desktop application that was written in C#. We also have a new .NET intranet web application written in asp.net 2.0. Is it possibly to have a button on the web application that when pressed will invoke the .NET 1.0 windows application? And then if someone closes the application, it will return control back to the ASP.NET 2.0 application?    Are you referring to running a WinForms application on the server or on the client PC? ...

Both C# ASPX pages and VB.NET ASPX in single VB.NET Web Applcation Template
Hi.. Is it possible to have both c# pages and VB pages in same Webapplication, what i chose is VB.NET Web application Template. With Thanks, Jaya.... I don't see why you couldn't, but for the sake of consistency I don't know why you would want to do this. When you choose a C# or VB.NET application template(I'm assuming you're using VS or WebMatrix), it simply creates a .aspx file that includes a page directive that specifies the page language. If you created a C# template but want to use VB.Net instead, you need to go from: <%@ Page Language="C#" .... to...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

VB.NET new item behavior in VS.NET
When I create a new class in VS.NET, it gives me a template like this: public class xxx end class How can I make it the same behavior as I got in C#? I mean: namespace defaultnamespace.folderpath public class xxx end class end namespace I can change the template in VS.NET, but can not figure out a way to specify a default namespace, and can not find a way to include the folder path in namespace. Thanks, CalvinLive by a Better Codehttp://www.raincoder.comEqual parts art and scienceEmail: cguo@raincoder.com...

Web resources about - updating label text based on selected item in a DropDownList (LINQ, VB.NET) - asp.net.web-forms

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/8/2015 12:29:52 AM