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
- -------First DDL
- <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SQLLEAVECODE"
- DataTextField="LEAVETYPE" DataValueField="LEAVECODE"
- onselectedindexchanged="DropDownList1_SelectedIndexChanged"
- AppendDataBoundItems="True" ViewStateMode="Enabled" AutoPostBack="True"
- SelectedValue='<%# BIND("REQLEAVECODE") %>' Width="80px">
- <asp:ListItem> </asp:ListItem>
- </asp:DropDownList>
- -------Second DDL
- <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource1"
- DataTextField="REASON" DataValueField="REASON"
- SelectedValue='<%# Bind("leavetype") %>'>
- </asp:DropDownList>
- ---------page load
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- DetailsView1.DataBind();
- }
- }
- --------DDL 1 selectedIndexChange
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- DropDownList lvtype = (DropDownList)(DetailsView1.FindControl("DropDownList6"));
- DropDownList lvreason = (DropDownList)(DetailsView1.FindControl("DropDownList5"));
- Label27.Text = lvtype.SelectedValue.ToString();
- DetailsView1.Fields[4].Visible = true;
- }