.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Read Datas from txt file and bind values to dropdownlist in ASP.NET

Posted By:Athira Sreejith       Posted Date: March 28, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  
 

Here i have one  state dropdownlist.while selecting state from state dropdownlist ,reading selected state's countries fromtxt file  and filling another dropdownlist.

 

if (ddlStatePost.SelectedValue.Trim() == "Maharashtra")

{

ddlDistrictPost.Items.Clear();

StreamReader read = new StreamReader(MapPath(Request.ApplicationPath + "\\" + "States" + "\\" + "Maharashtra.txt"));

string data;

ddlDistrictPost.Items.Add(new ListItem("----Select District----", "none"));

while (!string.IsNullOrEmpty((data = read.ReadLine())))

{

ddlDistrictPost.Items.Add(new ListItem(data.Trim(), data.Trim()));

}

}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend