Wrox Programmer Forums
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 28th, 2008, 10:15 AM
Authorized User
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default SelectedIndex in datalist

I have a datalist that bind several dropdownlists from various tables. Well two of the dropdownlist are dependent upon the other. For example, if ddl1.SelectedValue = "1" then ddl2.selectedvalue = '01'. If ddl1.SelectedValue ="2" then ddl2.selectedvalue = '02'. If it was outside of a datalist then I would have no problem doing it. But instead this datalist is really throwing me off. Any suggestions. I'm not sure whether or not to use ItemDataBound or dlSelectedIndexChange. Here my code that I have thus far. Right now it's throwing the error "Object reference not specified" on the line
 'prmCauseDetail.Value = ddlcausetype.SelectedItem.Value'

Private Sub BindCauseDetails(ByVal ddl As DropDownList)

        connFF = New SqlConnection(Application("connFF"))
        Dim ddlcausetype As DropDownList
        Dim intCounter As Integer
        Dim ddlCauseDetails As DropDownList
        Dim cmdCauseDetails As New SqlCommand("spFFGetCauseDetails", connFF)
        cmdCauseDetails.CommandType = CommandType.StoredProcedure

        Dim prmCauseDetail As New SqlParameter("@CauseType", SqlDbType.VarChar)
        prmCauseDetail.Value = ddlcausetype.SelectedItem.Value

        Dim dtrDetails As SqlDataReader

            dtrDetails = cmdCauseDetails.ExecuteReader
            ddlCauseDetails.DataSource = dtrDetails
            ddlCauseDetails.DataTextField = "Details"
            ddlCauseDetails.DataValueField = "Details"


        Catch er As Exception
            LogError(er.ToString, "CauseDetails-Incident.aspx")
            Exit Try
        End Try
    End Sub

    Sub dlIncident_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dlIncident.SelectedIndexChanged
        Dim ddlCausedetails As DropDownList
    End Sub

<asp:DropDownList id="ddlcausetype" runat="server" OnSelectedIndexChanged="dlIncident_SelectedIndexCh anged"
                                        Width="272px" ForeColor="Gray" AutoPostBack="True"></asp:DropDownList></TD>

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set selectedindex azitanosrati General .NET 16 December 1st, 2006 02:25 PM
GridView.SelectedIndex Prop SteveP55419 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 8th, 2006 09:08 PM
DropDownList selectedindex retrieval poison_king ASP.NET 1.0 and 1.1 Professional 5 September 21st, 2004 09:44 AM
Grab SelectedIndex Number phungleon Classic ASP Basics 6 May 18th, 2004 10:14 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.