Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

controlX has a SelectedValue which is invalid because it does not exist in the list of items
I am trying to create a drop down list that is dependent on another
dropdown list value.

I have seen this site
http://www.webswapp.com/codesamples...ts/default.aspx

but I am unable to get it working.  The only things that I have
different is that the displayed text in both list is a text value and
the value is an integer and also I am using the insertitemtemplate.  I
have played with changing from selectedvalue to selected index, but no
dice.

Here is a code snippet:

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ServerID"
DataSourceID="DS_Servers" OnItemUpdating="FormView1_ItemUpdating">
<InsertItemTemplate>
<asp:SqlDataSource ID="DS_Rack" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [RackID], [Rack] FROM
[cRack]"></asp:SqlDataSource>
<asp:SqlDataSource ID="DS_Cabinet" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT [CabinetID], [Cabinet] FROM
[cCabinet] WHERE ([RackID] = @RackID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddRack" Name="RackID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<table>
<tr align="left">
<td>Rack Location</td>
<td>
<asp:DropDownList ID="ddRack" runat="server"
AutoPostBack="True" SelectedValue='<%# Bind("RackID") %>'
DataSourceID="DS_Rack" DataTextField="Rack"
DataValueField="RackID"></asp:DropDownList>
-
<asp:DropDownList ID="ddCabinet" runat="server"
SelectedValue='<%# Eval("CabinetID") %>' DataSourceID="DS_Cabinet"
DataTextField="Cabinet" DataValueField="CabinetID"
OnDataBound="ddCabinet_DataBound">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert"></asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>


Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal
e As FormViewUpdateEventArgs)
Dim Rack As Integer = CType(CType(sender,
FormView).FindControl("ddCabinet"), DropDownList).SelectedIndex
e.NewValues("Rack") = Rack
e.Cancel = False
End Sub
Protected Sub ddCabinet_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 RackID As Int32 = CType(frmV.DataItem,
Data.DataRowView)("Rack")
ddl.ClearSelection()
Dim li As ListItem = ddl.Items.FindByValue(RackID)
If Not li Is Nothing Then li.Selected = True
End If
End Sub

Any help would be greatly appreciated.


Report this thread to moderator Post Follow-up to this message
Old Post
dhizzy
02-08-06 02:49 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

ASP .NET Webcontrols archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 01:54 PM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.