Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.