; ComboBox DataBinding with XML in C#.net | SQL Server

Big Entertainment On Demand

Download APK  - Visit Here

ComboBox DataBinding with XML in C#.net


Know More :  ASP.Net  VB.Net  C#.Net  Sliverlight  XML  WPF  WCF Ajax
Let’s Start ComboBox DataBinding with XML in C-sharp  with Visual Studio 2010\2008\2005. This is very simple. Firstly you have to a xml file for this.Now in visual studio 2010 we create a new project name “Xml to Combobox”. As shown in figure..
ScreenShot069




After drag combobox control on form 1. Double click on form , declare namespace  using System.Xml; also change your xml file path.As shown in figure..
 ScreenShot070 
copy code and paste form_load……….
{// Declare a variable of type  XmlTextReader
     XmlTextReader xtr  = null;
     // Declare a string that holds the name of the file
     string fileName = "D:\\AC_backup\\product.xml";
     try {
         // Initialize the XmlTextReader variable with the name of the file
         xtr = new XmlTextReader(fileName);
         xtr.WhitespaceHandling = WhitespaceHandling.None;
         // Scan the XML file
         while (xtr.Read())
         {
             // every time you find an element, find out what type it is
             switch (xtr.NodeType)
             {
                 case XmlNodeType.Text:
                     // If you find text, put it in the combo box' list
                     this.comboBox1.Items.Add(xtr.Value);
                     break;
             }
         }
         // For this example, select the first item
         this.comboBox1.SelectedIndex = 0;
     }
     finally
     {
         // Close the XmlTextReader
         if (xtr != null)
             xtr.Close();
     }
        }
Now press f5 button , the form will be open and also  ComboBox DataBinding with XML completed. Thanks.
Know More :  ASP.Net  VB.Net  C#.Net  Sliverlight  XML  WPF  WCF Ajax
Share on Google Plus

About Sujay

Hi ! I am Sujay Sharma. I am working in Indian Railway as Guard. I am sharing my experience about Microsoft SQL Server with ASP.NET ,VB.NET,C#.NET,XML "" Thanks.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment