This is a discussion on Is there any way to load data in dropdownlist based on the other without Page Refresh within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, How to load data in dropdownlist based on other without refreshing the page and without using Ajax?.......
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| I too have that doubt. While selecting an item from a dropdownlist box,the page was refreshed and i had to loss the selected data and the first element was automatically selected. If you get the answer for this then please reply me. -Kirubha |
| |||
| Hi, We can avoid full page refreshment while loading data in dropDownlist using XML.For this u need the XML File to be generated for ur table. Here i used countryContent.xml which contains both country and its related state. protected void Page_Load(object sender, EventArgs e) { DataTable dataTable = new DataTable(); DataRow dr; dataTable.Columns.Add("countryName",typeof(string) ); if (!IsPostBack) { XmlDocument xdoc = new XmlDocument(); XmlTextReader xtr = new XmlTextReader(Server.MapPath("countryContent.xml") ); xdoc.Load(xtr); XmlNodeList xnl = xdoc.DocumentElement.SelectNodes("country"); foreach (XmlNode xnode in xnl) { dr = dataTable.NewRow(); dr[0] = xnode.Attributes[0].Value; dataTable.Rows.Add(dr); } countryDropDownList.DataSource = dataTable; countryDropDownList.DataValueField = "countryName"; countryDropDownList.DataBind(); } } protected void countryDropDownList_SelectedIndexChanged(object sender, EventArgs e) { stateDropDownList.Items.Clear(); GetStateFromCountry(); } public void GetStateFromCountry() { int flag = 0; DataTable dataTable = new DataTable(); DataRow dr; dataTable.Columns.Add("stateName", typeof(string)); XmlDocument xdoc = new XmlDocument(); XmlNode snode=null; XmlTextReader xtr = new XmlTextReader(Server.MapPath("countryContent.xml") ); xdoc.Load(xtr); XmlNodeList xnl = xdoc.DocumentElement.SelectNodes("country"); foreach (XmlNode xnode in xnl) { if (xnode.Attributes[0].Value == countryDropDownList.SelectedItem.Text) { flag = 1; snode = xnode; } } if (flag == 1) { XmlNodeList stateNodeList = snode.ChildNodes; foreach (XmlNode xsnode in stateNodeList) { dr = dataTable.NewRow(); dr[0] = xsnode.Attributes[1].Value; dataTable.Rows.Add(dr); } } stateDropDownList.DataSource = dataTable; stateDropDownList.DataTextField = "stateName"; stateDropDownList.DataBind(); } try this..only partial refresh is there..That is u cant get whole page refreshed instead u will have min refreshment.I hope this helps to avoid full page refreshment. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/5161-there-any-way-load-data-dropdownlist-based-other-without-page-refresh.html | |||
| Posted By | For | Type | Date |
| Is there any way to load data in dropdownlist based on the other without Page... - Ajax | This thread | Refback | 02-24-2008 01:07 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to bind values of onedropdownlist to another dropdownlist in another page? | poornima | ASP and ASP.NET Programming | 0 | 02-03-2008 09:07 PM |
| What methods are fired during the page load? | prasath | ASP and ASP.NET Programming | 1 | 07-18-2007 03:04 AM |
| How can I automatically load another page or reload the same page? | Archer | C# Programming | 0 | 07-16-2007 12:10 AM |
| Refresh a page through Javascript | Sathish Kumar | HTML, CSS and Javascript Coding Techniques | 0 | 07-02-2007 07:35 AM |
| Refresh Page for a Certain Time of Interval | Anandavinayagam | ASP and ASP.NET Programming | 2 | 03-19-2007 04:59 AM |