473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DropDownList Autopostback clears fields, reverts to default

Hi,

I have two drop down lists inside of two different fields in a detailsview, the first one determines the values of the second one.

When i select a value from the first ddl autopostback erases all data already in the detailsview and reverts the first dropdownlist back to the first selection.

Also when i select from the list (change the ddl selection more than once) it will throw a :

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Source Error:

[No relevant source lines]

Expand|Select|Wrap|Line Numbers
  1. -------First DDL
  2.  
  3.      <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SQLLEAVECODE"
  4.              DataTextField="LEAVETYPE" DataValueField="LEAVECODE"
  5.              onselectedindexchanged="DropDownList1_SelectedIndexChanged"
  6.              AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
  7.              SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="80px">
  8.              <asp:ListItem> </asp:ListItem>
  9.       </asp:DropDownList>
  10.  
  11. -------Second DDL
  12.  
  13.     <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
  14.           DataTextField="REASON" DataValueField="REASON" 
  15.           SelectedValue='<%# Bind("leavetype") %>'>
  16.     </asp:DropDownList>
  17.  
  18.  
  19.  
  20. ---------page load
  21.         protected void Page_Load(object sender, EventArgs e)
  22.         {
  23.             if (!IsPostBack)
  24.             {
  25.                 DetailsView1.DataBind();
  26.             }
  27.         }
  28.  
  29.  
  30. --------DDL 1 selectedIndexChange
  31.         protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  32.         {
  33.             DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
  34.             DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
  35.             Label27.Text = lvtype.SelectedValue.ToString();
  36.  
  37.             DetailsView1.Fields[4].Visible = true;
  38.         }
Aug 13 '12 #1
7 3593
ariful alam
185 100+
What do you need actually? Do you need to change the value in DropDownList_2 those linked to value of DropDownList_1 in every selection of DropDownList_1?
Aug 14 '12 #2
Yes, DropDownList_1 needs to change the values in list 2 ... but some of the values of DropDownList_1 need to be the exact value of DropDownList_2 if there is no other values that correspond to DropDownList_1 in DropDownList_2.

For example, Sick Leave will be in DropDownList_1 and it will have 6 different options in DropDownList_2. But Personal Holiday in DropDownList_1 will only have one option in DropDownList_2 which will be itself, personal holiday
Aug 14 '12 #3
ariful alam
185 100+
to change automatically the values of list_2 because of selecting an item from list_1, you can use Microsoft Ajax Toolkit. This is the best to do this. you can see an example here(http://www.asp.net/ajaxLibrary/AjaxC...gDropDown.aspx). to download Microsoft Ajax Toolkit visit http://ajaxcontroltoolkit.codeplex.com/

Now the second requirement. Basically, the list values come from database tables. like for first list i may use Category Table and for second list i may use Sub_category Table. If any record in Category Table has no linked record in Sub_category Table, i used to store the same record of Category Table in Sub_category Table as linked data. So, the selection of an item in list_1 also shows in list_2.
Aug 14 '12 #4
Thank you!

That solution did partially work, but the only problem with it is i have to select the first DropDownList1 value twice for it to stay loaded, autopostback still clears all fields the first time, but the dropdownlists seem to be responding properly other than that.
Aug 14 '12 #5
Sorry, Actually it worked for a few times but now it is immediatly throwing this error


Expand|Select|Wrap|Line Numbers
  1. Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
  2.  
  3. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  4.  
  5. Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
  6.  
  7. Source Error: 
  8.  
  9.  
  10. [No relevant source lines]
  11.  
  12. Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\9b1781c5\212dfe37\App_Web_0td2wxdy.1.cs    Line: 0 
  13.  
  14. Stack Trace: 
  15.  
  16.  
  17. [InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.]
  18.    System.Web.UI.Page.GetDataItem() +2802118
  19.    ASP.authorized_leaverequest_newrequestform_aspx.__DataBinding__control69(Object sender, EventArgs e) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\9b1781c5\212dfe37\App_Web_0td2wxdy.1.cs:0
  20.    System.Web.UI.Control.OnDataBinding(EventArgs e) +91
  21.    System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +14
  22.    System.Web.UI.WebControls.ListControl.PerformSelect() +34
  23.    System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
  24.    System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
  25.    System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +29
  26.    System.Web.UI.Control.PreRenderRecursiveInternal() +103
  27.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  28.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  29.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  30.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  31.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  32.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  33.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  34.    System.Web.UI.Control.PreRenderRecursiveInternal() +175
  35.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
Aug 14 '12 #6
ariful alam
185 100+
Is that error comes because of DropDownLists?

Do you tested the cascading dropdownlist of Microsoft Ajax Toolkit?

Whats are in your page? can you attach your .aspx and .cs file here with the database table files that require for this?
Aug 14 '12 #7
Sorry I cannot post the tables required for this. The cascading dropdownlist isnt working well because it is in a detailsview and the ddls are in seperate fields.

Thank you for all your help though.
Aug 15 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Corey | last post by:
I'm trying to finish off do an ASP.NET project where a DropDownList box is used to access a Table. Once you Make a selection on an item in the DropDownListBox, it updates a DataView, and text...
5
by: sri | last post by:
I have a usercontrol that has the dropdownlist which has Autopostback set to true. The selectedindex changed event is not getting fired from IE if the production webserver has ASP.NET 1.1.4322.573...
0
by: PJ | last post by:
Beautiful...apparently the dropdownlist control renders the language="javascript" attribute if you set the autopostback to true. This is not valid XHTML. Is there a way to prevent this outside...
3
by: indigator | last post by:
I am using ASP.NET 2.0. I have 2 dropdownlists in my page. One holds the list of all the countries and other holds the list of all States. When the user selects the country as United States, I want...
5
by: robert | last post by:
I have a dropdownlist with the autopostback set to true. I want the user to be confirm whether they do indeed want to change the value, which on post back fires a server side event...
0
by: andy | last post by:
Hi, I have a form uses several dropdownlists to narrow a set of criteria. ( This is in turn used to control what is shown on a gridview. ) With each, the user selects an entry and then the next...
0
by: Med | last post by:
Hi, I have two dropDown lists ddlCars and ddlModels. ddlCars AutoPostBack="true" to populate the ddlModels when a car is selected. If the page is not valid (i.e. user left a mandatory textbox...
3
by: MU | last post by:
Hello I have a form with a dropdownlist on it and in the page_load I have this to populate it: Dim productsAdapter As New ProductsTableAdapter drpProducts.DataSource =...
27
by: user1980 | last post by:
hello, i am trying to create a request form using asp.net where when a user selects a checkbox, a dropdown should appear dynamically. I have seen few java-scripts in web, but I was wondering if I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.