Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdownlist not declared in script when DDL is in DetailsView

Status
Not open for further replies.

ola123

Technical User
Sep 16, 2005
52
JM
Hello guys,
thanks for the help in advance

My problem is that whatever input or selection control i have in the detailsview (specifically in the edititemtemplate) the control's ID id never declared in the script. What could be the reason for this?

I was thinking that probably a function is to be returned to the script (thats just my guess anyway).

My code is below, the purpose is to have a dropdownlist that populates another DDL

Code:
<script runat="server">
    Sub Generate(ByVal a As Object, ByVal y As EventArgs)
        
        Dim ddl As DropDownList
        Dim ddl2 As DropDownList
        Dim lbl As Label
        
        If ddl.SelectedValue = 1 Then
            lbl.Text = "value 1 selected"
            ddl2.Items.Clear()
            ddl2.Items.Add(New ListItem("CABS", "1"))
            ddl2.Items.Add(New ListItem("MIS", "2"))
        ElseIf ddl.SelectedValue = 2 Then
            lbl.Text = "value 2 selected"
            ddl2.Items.Clear()
            ddl2.Items.Add(New ListItem("BBA", "1"))
            ddl2.Items.Add(New ListItem("ADB", "2"))
        End If             
    End Sub
</script>

<html>
<head runat="server">
    <title>Nested Dropdownlist</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:AccessDataSource ID="ADS" runat="server" DataFile="registry.mdb"
            SelectCommand="SELECT * FROM CSDept ">
        </asp:AccessDataSource>
        
        <asp:Detailsview runat="server" id="DV" DataSourceID="ADS"
        allowpaging=true AutoGenerateRows=false AutoGenerateEditButton=true >
                
        <fields>
            <asp:BoundField
            headertext="ID No."
            datafield="id" />
            
            <asp:boundfield
            headertext="First Name"
            datafield="fname"/>
            
            <asp:boundfield
            headertext="Last Name"
            datafield="lname"/>
            
            <asp:templatefield HeaderText="Programme">
                <editItemTemplate>
                    <asp:DropDownList ID="DDL" runat="server" AutoPostBack=true OnTextChanged="generate">
                        <asp:ListItem Value=1>Computer</asp:ListItem>
                        <asp:ListItem Value=2>Business</asp:ListItem>
                    </asp:DropDownList>
        
                    <asp:dropdownlist runat="server" ID="ddl2" Width="100"></asp:dropdownlist>
                </editItemTemplate>
            </asp:templatefield>
        
        </fields>
        
        </asp:detailsview>
     </form>
</body>
</html>
Thanks for the help in advance
Peace

Cool Nuh Man
 
You need to assign that DropDownList to a variable. Look at "FindControl" to do this.

google "asp.net dropdownlist edit template findcontrol" for some help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top