"ddl has a SelectedValue which is invalid" Error goes away after restarting browser


B

Brett

I have an application that contains two databound DropDownLists. Selecting
a department from the first ddl causes a DropDownList of machines to be
populated.

One of the users enters several new records back-to-back, and she reported
that she often gets the error, "'ddlMachine' has a SelectedValue which is
invalid because it does not exist in the list of items", after selecting a
value from ddlDepartment in insert mode. At that point, she must close
the browser and re-open it to prevent the error from occurring again.
Then, everything is fine, until she has saved a few more entries.

At first, I was unable to duplicate this. The next day, I was able to
duplicate it, and it happened every time I selected a value from
ddlDepartment. At that point, I got diverted by a phone call and did
not get back to it for about 45 minutes. When I returned, the application
worked fine again!

It seems as though something is not getting cleared properly from memory on
the web server. Restarting Internet Explorer or just being inactive for a
while seems to correct the problem. If this is the problem, is there some
way that I can force this to get cleared from memory?

I have included code below.

Thanks in advance!
Brett


ASPX:

<asp:FormView ID="FormView1" runat="server"
DataMember="DefaultView"
DataSourceID="WorkOrderSqlDataSource"
DataKeyNames="SSRID" CssClass="Panels"
OnItemUpdating="FormView1_ItemUpdating">
<InsertItemTemplate>
<asp:SqlDataSource ID="DeptSqlDataSource"
runat="server"
ConnectionString="<%$ConnectionStrings:SSR_ConnString %>"
SelectCommand="SELECT [DepartmentName] FROM
[Department] ORDER BY PositionInDropDownList"
DataSourceMode="DataReader">
</asp:SqlDataSource>

<asp:SqlDataSource ID="MachineSqlDataSource"
runat="server"
ConnectionString="<%$ConnectionStrings:SSR_ConnString %>"
SelectCommand="SELECT [MachineName], [MachineID]
FROM [Machine] WHERE ([Line] = @Line)"
DataSourceMode="DataReader">
<SelectParameters>
<asp:ControlParameter ControlID="ddlDepartment"
Name="Line"
PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>

<asp:DropDownList ID="ddlDepartment"
runat="server"
CssClass="DetailsViewItemStyle"
AutoPostBack="True" Width="13em"
AppendDataBoundItems="true"
DataSourceID="DeptSQLDataSource"
DataTextField="DepartmentName"
DataValueField="DepartmentName"
OnPreRender="ShowAdminFields"
SelectedValue='<%# Bind("DepartmentName") %>' >
</asp:DropDownList>

<asp:DropDownList ID="ddlMachine"
runat="server"
CssClass="DetailsViewItemStyle"
Width="17em"
DataSourceID="MachineSQLDataSource"
DataTextField="MachineName"
DataValueField="MachineName" >
<asp:ListItem></asp:ListItem>
</asp:DropDownList>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="ddlMachine"
cssclass="Validator"
Display="Dynamic"
ErrorMessage="<== Required field" />


ASPX.VB:

Protected Sub ddlDepartment_DataBound(ByVal sender As Object, ByVal e As
EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
Dim frmV As FormView = CType(ddl.NamingContainer, FormView)
If Not frmV.DataItem Is Nothing Then
'Pull the department value from the databound item
Dim sDepartment As String = CType(frmV.DataItem,
DataRowView)("DepartmentName")
ddl.ClearSelection()
Dim li As ListItem = ddl.Items.FindByValue(sDepartment)
If Not li Is Nothing Then li.Selected = True
End If

'Since the machine selection is dependent on the department, we have
'to databind the machine list after changing the department
'selection.
ddl = CType(frmV.FindControl("ddlMachine"), DropDownList)
If Not ddl Is Nothing Then ddl.DataBind()
End Sub

Protected Sub ddlMachine_DataBound(ByVal sender As Object, ByVal e As
EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
Dim frmV As FormView = CType(ddl.NamingContainer, FormView)
If Not frmV.DataItem Is Nothing Then
Dim sMachine As String = CType(frmV.DataItem,
DataRowView)("MachineName")
ddl.ClearSelection()
Dim li As ListItem = ddl.Items.FindByValue(sMachine)
If Not li Is Nothing Then li.Selected = True
End If
End Sub

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting
Dim sDepartment As String = CType(CType(sender,
FormView).FindControl("ddlDepartment"), DropDownList).SelectedValue
e.Values("DepartmentName") = sDepartment
Dim sMachine As String = CType(CType(sender,
FormView).FindControl("ddlMachine"), DropDownList).SelectedValue
e.Values("MachineName") = sMachine
e.Cancel = False
End Sub

Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles
FormView1.ItemUpdating
Dim sDepartment As String = CType(CType(sender,
FormView).FindControl("ddlDepartment"), DropDownList).SelectedValue
e.NewValues("DepartmentName") = sDepartment
Dim sMachine As String = CType(CType(sender,
FormView).FindControl("ddlMachine"), DropDownList).SelectedValue
e.NewValues("MachineName") = sMachine
e.Cancel = False
End Sub
 
Ad

Advertisements

A

Allen Chen [MSFT]

Hi Brett,

==================================================
It seems as though something is not getting cleared properly from memory on
the web server. Restarting Internet Explorer or just being inactive for a
while seems to correct the problem. If this is the problem, is there some
way that I can force this to get cleared from memory?
==================================================

From your description above I would guess it's related to cache. Have you
ever used cache in your application?

To investigate this issue further I need a demo project (including
database). I don't think It's that easy to repro this issue with the code
you provided. If you have successfully created a demo project please send
it to me directly, my email is (e-mail address removed). Please also let me
know if you find any clues that may help to solve this issue. In the
meantime I'll try to repro this issue with your code.

Regards,
Allen Chen
Microsoft Online Support

--------------------
| From: "Brett" <[email protected]>
| Subject: "ddl has a SelectedValue which is invalid" Error goes away
after restarting browser
| Date: Wed, 8 Oct 2008 16:43:49 -0400
| Lines: 157
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: dsl-1-210.d01.scpnbh.pbtcomm.net 64.53.27.210
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:77547
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have an application that contains two databound DropDownLists.
Selecting
| a department from the first ddl causes a DropDownList of machines to be
| populated.
|
| One of the users enters several new records back-to-back, and she reported
| that she often gets the error, "'ddlMachine' has a SelectedValue which is
| invalid because it does not exist in the list of items", after selecting a
| value from ddlDepartment in insert mode. At that point, she must close
| the browser and re-open it to prevent the error from occurring again.
| Then, everything is fine, until she has saved a few more entries.
|
| At first, I was unable to duplicate this. The next day, I was able to
| duplicate it, and it happened every time I selected a value from
| ddlDepartment. At that point, I got diverted by a phone call and did
| not get back to it for about 45 minutes. When I returned, the application
| worked fine again!
|
| It seems as though something is not getting cleared properly from memory
on
| the web server. Restarting Internet Explorer or just being inactive for a
| while seems to correct the problem. If this is the problem, is there some
| way that I can force this to get cleared from memory?
|
| I have included code below.
|
| Thanks in advance!
| Brett
|
|
| ASPX:
|
| <asp:FormView ID="FormView1" runat="server"
| DataMember="DefaultView"
| DataSourceID="WorkOrderSqlDataSource"
| DataKeyNames="SSRID" CssClass="Panels"
| OnItemUpdating="FormView1_ItemUpdating">
| <InsertItemTemplate>
| <asp:SqlDataSource ID="DeptSqlDataSource"
| runat="server"
| ConnectionString="<%$ConnectionStrings:SSR_ConnString %>"
| SelectCommand="SELECT [DepartmentName] FROM
| [Department] ORDER BY PositionInDropDownList"
| DataSourceMode="DataReader">
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="MachineSqlDataSource"
| runat="server"
| ConnectionString="<%$ConnectionStrings:SSR_ConnString %>"
| SelectCommand="SELECT [MachineName], [MachineID]
| FROM [Machine] WHERE ([Line] = @Line)"
| DataSourceMode="DataReader">
| <SelectParameters>
| <asp:ControlParameter ControlID="ddlDepartment"
| Name="Line"
| PropertyName="SelectedValue"
| Type="String" />
| </SelectParameters>
| </asp:SqlDataSource>
|
| <asp:DropDownList ID="ddlDepartment"
| runat="server"
| CssClass="DetailsViewItemStyle"
| AutoPostBack="True" Width="13em"
| AppendDataBoundItems="true"
| DataSourceID="DeptSQLDataSource"
| DataTextField="DepartmentName"
| DataValueField="DepartmentName"
| OnPreRender="ShowAdminFields"
| SelectedValue='<%# Bind("DepartmentName") %>' >
| </asp:DropDownList>
|
| <asp:DropDownList ID="ddlMachine"
| runat="server"
| CssClass="DetailsViewItemStyle"
| Width="17em"
| DataSourceID="MachineSQLDataSource"
| DataTextField="MachineName"
| DataValueField="MachineName" >
| <asp:ListItem></asp:ListItem>
| </asp:DropDownList>
|
| <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
| runat="server"
| ControlToValidate="ddlMachine"
| cssclass="Validator"
| Display="Dynamic"
| ErrorMessage="<== Required field" />
|
|
| ASPX.VB:
|
| Protected Sub ddlDepartment_DataBound(ByVal sender As Object, ByVal e
As
| EventArgs)
| Dim ddl As DropDownList = CType(sender, DropDownList)
| Dim frmV As FormView = CType(ddl.NamingContainer, FormView)
| If Not frmV.DataItem Is Nothing Then
| 'Pull the department value from the databound item
| Dim sDepartment As String = CType(frmV.DataItem,
| DataRowView)("DepartmentName")
| ddl.ClearSelection()
| Dim li As ListItem = ddl.Items.FindByValue(sDepartment)
| If Not li Is Nothing Then li.Selected = True
| End If
|
| 'Since the machine selection is dependent on the department, we
have
| 'to databind the machine list after changing the department
| 'selection.
| ddl = CType(frmV.FindControl("ddlMachine"), DropDownList)
| If Not ddl Is Nothing Then ddl.DataBind()
| End Sub
|
| Protected Sub ddlMachine_DataBound(ByVal sender As Object, ByVal e As
| EventArgs)
| Dim ddl As DropDownList = CType(sender, DropDownList)
| Dim frmV As FormView = CType(ddl.NamingContainer, FormView)
| If Not frmV.DataItem Is Nothing Then
| Dim sMachine As String = CType(frmV.DataItem,
| DataRowView)("MachineName")
| ddl.ClearSelection()
| Dim li As ListItem = ddl.Items.FindByValue(sMachine)
| If Not li Is Nothing Then li.Selected = True
| End If
| End Sub
|
| Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e
As
| System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
| FormView1.ItemInserting
| Dim sDepartment As String = CType(CType(sender,
| FormView).FindControl("ddlDepartment"), DropDownList).SelectedValue
| e.Values("DepartmentName") = sDepartment
| Dim sMachine As String = CType(CType(sender,
| FormView).FindControl("ddlMachine"), DropDownList).SelectedValue
| e.Values("MachineName") = sMachine
| e.Cancel = False
| End Sub
|
| Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e
As
| System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles
| FormView1.ItemUpdating
| Dim sDepartment As String = CType(CType(sender,
| FormView).FindControl("ddlDepartment"), DropDownList).SelectedValue
| e.NewValues("DepartmentName") = sDepartment
| Dim sMachine As String = CType(CType(sender,
| FormView).FindControl("ddlMachine"), DropDownList).SelectedValue
| e.NewValues("MachineName") = sMachine
| e.Cancel = False
| End Sub
|
|
|
|
|
|
|
|
|
|
|
|
 
Ad

Advertisements

A

Allen Chen [MSFT]

Hi Brett,

Do you have any progress on this issue? If you find any clues please do let
me know. If you have successfully created a demo project please email it to
me.

Regards,
Allen Chen
Microsoft Online Support
--------------------
| From: "Brett" <[email protected]>
| Subject: "ddl has a SelectedValue which is invalid" Error goes away
after restarting browser
| Date: Wed, 8 Oct 2008 16:43:49 -0400
| Lines: 157
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: dsl-1-210.d01.scpnbh.pbtcomm.net 64.53.27.210
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:77547
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have an application that contains two databound DropDownLists.
Selecting
| a department from the first ddl causes a DropDownList of machines to be
| populated.
|
| One of the users enters several new records back-to-back, and she reported
| that she often gets the error, "'ddlMachine' has a SelectedValue which is
| invalid because it does not exist in the list of items", after selecting a
| value from ddlDepartment in insert mode. At that point, she must close
| the browser and re-open it to prevent the error from occurring again.
| Then, everything is fine, until she has saved a few more entries.
|
| At first, I was unable to duplicate this. The next day, I was able to
| duplicate it, and it happened every time I selected a value from
| ddlDepartment. At that point, I got diverted by a phone call and did
| not get back to it for about 45 minutes. When I returned, the application
| worked fine again!
|
| It seems as though something is not getting cleared properly from memory
on
| the web server. Restarting Internet Explorer or just being inactive for a
| while seems to correct the problem. If this is the problem, is there some
| way that I can force this to get cleared from memory?
|
| I have included code below.
|
| Thanks in advance!
| Brett
|
|
| ASPX:
|
| <asp:FormView ID="FormView1" runat="server"
| DataMember="DefaultView"
| DataSourceID="WorkOrderSqlDataSource"
| DataKeyNames="SSRID" CssClass="Panels"
| OnItemUpdating="FormView1_ItemUpdating">
| <InsertItemTemplate>
| <asp:SqlDataSource ID="DeptSqlDataSource"
| runat="server"
| ConnectionString="<%$ConnectionStrings:SSR_ConnString %>"
| SelectCommand="SELECT [DepartmentName] FROM
| [Department] ORDER BY PositionInDropDownList"
| DataSourceMode="DataReader">
| </asp:SqlDataSource>
|
| <asp:SqlDataSource ID="MachineSqlDataSource"
| runat="server"
| ConnectionString="<%$ConnectionStrings:SSR_ConnString %>"
| SelectCommand="SELECT [MachineName], [MachineID]
| FROM [Machine] WHERE ([Line] = @Line)"
| DataSourceMode="DataReader">
| <SelectParameters>
| <asp:ControlParameter ControlID="ddlDepartment"
| Name="Line"
| PropertyName="SelectedValue"
| Type="String" />
| </SelectParameters>
| </asp:SqlDataSource>
|
| <asp:DropDownList ID="ddlDepartment"
| runat="server"
| CssClass="DetailsViewItemStyle"
| AutoPostBack="True" Width="13em"
| AppendDataBoundItems="true"
| DataSourceID="DeptSQLDataSource"
| DataTextField="DepartmentName"
| DataValueField="DepartmentName"
| OnPreRender="ShowAdminFields"
| SelectedValue='<%# Bind("DepartmentName") %>' >
| </asp:DropDownList>
|
| <asp:DropDownList ID="ddlMachine"
| runat="server"
| CssClass="DetailsViewItemStyle"
| Width="17em"
| DataSourceID="MachineSQLDataSource"
| DataTextField="MachineName"
| DataValueField="MachineName" >
| <asp:ListItem></asp:ListItem>
| </asp:DropDownList>
|
| <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
| runat="server"
| ControlToValidate="ddlMachine"
| cssclass="Validator"
| Display="Dynamic"
| ErrorMessage="<== Required field" />
|
|
| ASPX.VB:
|
| Protected Sub ddlDepartment_DataBound(ByVal sender As Object, ByVal e
As
| EventArgs)
| Dim ddl As DropDownList = CType(sender, DropDownList)
| Dim frmV As FormView = CType(ddl.NamingContainer, FormView)
| If Not frmV.DataItem Is Nothing Then
| 'Pull the department value from the databound item
| Dim sDepartment As String = CType(frmV.DataItem,
| DataRowView)("DepartmentName")
| ddl.ClearSelection()
| Dim li As ListItem = ddl.Items.FindByValue(sDepartment)
| If Not li Is Nothing Then li.Selected = True
| End If
|
| 'Since the machine selection is dependent on the department, we
have
| 'to databind the machine list after changing the department
| 'selection.
| ddl = CType(frmV.FindControl("ddlMachine"), DropDownList)
| If Not ddl Is Nothing Then ddl.DataBind()
| End Sub
|
| Protected Sub ddlMachine_DataBound(ByVal sender As Object, ByVal e As
| EventArgs)
| Dim ddl As DropDownList = CType(sender, DropDownList)
| Dim frmV As FormView = CType(ddl.NamingContainer, FormView)
| If Not frmV.DataItem Is Nothing Then
| Dim sMachine As String = CType(frmV.DataItem,
| DataRowView)("MachineName")
| ddl.ClearSelection()
| Dim li As ListItem = ddl.Items.FindByValue(sMachine)
| If Not li Is Nothing Then li.Selected = True
| End If
| End Sub
|
| Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e
As
| System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
| FormView1.ItemInserting
| Dim sDepartment As String = CType(CType(sender,
| FormView).FindControl("ddlDepartment"), DropDownList).SelectedValue
| e.Values("DepartmentName") = sDepartment
| Dim sMachine As String = CType(CType(sender,
| FormView).FindControl("ddlMachine"), DropDownList).SelectedValue
| e.Values("MachineName") = sMachine
| e.Cancel = False
| End Sub
|
| Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e
As
| System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles
| FormView1.ItemUpdating
| Dim sDepartment As String = CType(CType(sender,
| FormView).FindControl("ddlDepartment"), DropDownList).SelectedValue
| e.NewValues("DepartmentName") = sDepartment
| Dim sMachine As String = CType(CType(sender,
| FormView).FindControl("ddlMachine"), DropDownList).SelectedValue
| e.NewValues("MachineName") = sMachine
| e.Cancel = False
| End Sub
|
|
|
|
|
|
|
|
|
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top