Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a xml file
XML
<Student>
  <Students Name="StudentName" Type="string" symbol="=,%,!=" /> 
  <Students Name="EmployeeName" Type="string" symbol="=,%,!=" /> 
  <Students Name="ManagerName" Type="undefines" symbol="=,%,!=" /> 
  <undefined value="1" Name="Manager1">
  <undefined value="2" Name="Manager2">
  <Students Name="Level1" Type="string" Operators="=,%,!=" /> 
  <Students Name="Level2" Type="undefines" Operators="=,%,!=" /> 


I want to read this xml file and bind this to a dropdown which contains name in one dropdown .
On selection of drpdownName it shows the symbol associated with it . means for student name it shows = % != in the form of drop down .

Can anyone help me
How i read it and show it in dropdown
Posted
Comments
Deependra Khangarot 24-Mar-13 1:42am    
Hi Vimal,

Please clarify what exactly you want to accomplish.
Do you want to select name in one dropdown and on the basis of this selection want to show values in another dropdown?
Vimalrashamra 24-Mar-13 1:47am    
Name in first drop down
symbol in second one --- >
for example if i select Name then symbol in next dropdown will be ddl[0] = '=',ddl[1]= '%',ddl[2]= '!=' ...... hope u understand

1 solution

Add two dropdown lists to your aspx page.
Call below function on page load:

C#
public void LoadXML()
       {
           string myXMLfile = Server.MapPath("~/YourFile.xml");
           DataSet ds = new DataSet();
           try
           {
               dsStudent.ReadXml(myXMLfile);
               DropDownList1.DataSource = ds;
               DropDownList1.DataValueField = "Name";
               DropDownList1.DataTextField = "Name";
               DropDownList1.DataBind();

               DropDownList2.DataSource = ds;
               DropDownList2.DataValueField = "Name";
               DropDownList2.DataTextField = "symbol";
               DropDownList2.DataBind();


           }
           catch (Exception ex)
           {
               Response.Write(ex.ToString());
           }
       }



Add SlectedIndex change event to DropDownList1:

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

  DropDownList2.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;

}




Don't forget to mark useful responses as Answer if they helped you towards a solution.
 
Share this answer
 
Comments
Vimalrashamra 24-Mar-13 2:57am    
Thanks but its not working for me ..... :(
Deependra Khangarot 24-Mar-13 3:08am    
can you post your code and xml file content in proper format?
Vimalrashamra 24-Mar-13 3:35am    
actually i need to use xml document .....
because i am writing the xml file and reading it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900