Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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 February 18th, 2007, 02:48 AM
Registered User
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to slaverymorgue Send a message via Yahoo to slaverymorgue
Default SelectedIndexChanged DDL-->in Datagrid


I am having a huge problem with getting the selected index changed property of a drop down list when inside a datagrid..

I have two drop down lists inside the datagrid, toSectDDL and tosubSectDDL. What i want is when the user selects an item from the toSectDDL, the tosubSectDDL should be populated with the related subsections for that particular section only..

I have written the VB code as
Protected Sub toSectDDL_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
       Dim row As DataGridItem
       For Each row In SectionGrid.Items
           Dim toSectDDL As DropDownList = CType(SectionGrid.FindControl("toSectDDL"), DropDownList)
           Dim toSubSectDDL As DropDownList = CType(SectionGrid.FindControl("toSubSectDDL"), DropDownList)
           If toSectDDL.SelectedValue = 0 Then
               toSubSectDDL.Items.Insert(0, New ListItem("None", "0"))

               toSubSectDDL.DataSource = Office.GetSubSectionsForSection(toSectDDL.Selected Value)
               toSubSectDDL.DataTextField = "subsection"
               toSubSectDDL.DataValueField = "subSecID"
               toSubSectDDL.Items.Insert(0, New ListItem("Select", "0"))
           End If
   End Sub

and set the ASP code as
<asp:TemplateColumn HeaderText="toSection">
<asp:DropDownList id="toSectDDL" runat="server" CssClass="standardDDL" Width="402px" OnSelectedIndexChanged="toSectDDL_SelectedIndexCha nged" AutoPostBack="True" ></asp:DropDownList>
Now i am getting a server error saying
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
  veyo.OfficeNameChange.toSectDDL_SelectedIndexChang ed(Object sender, EventArgs e) in \\aion\intranetroot$\veyo\updateVEYO\OfficeNameCha nge.aspx.vb:430
  System.Web.UI.WebControls.ListControl.OnSelectedIn dexChanged(EventArgs e) +108
  System.Web.UI.WebControls.DropDownList.System.Web. UI.IPostBackDataHandler.RaisePostDataChangedEvent( ) +26
  System.Web.UI.Page.RaiseChangedEvents() +115
  System.Web.UI.Page.ProcessRequestMain() +1099

Can anyone plz help!!!!!!

Old February 19th, 2007, 09:30 AM
Authorized User
Join Date: Jan 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts


This link might help you.



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can selectedvalue of DDL make other DDL visibl hertendreef ASP.NET 2.0 Professional 4 May 20th, 2008 04:38 PM
DropDownList into DataGrid-Every Row has a DDL su C# 2005 2 November 30th, 2006 10:23 AM
DropDownList into DataGrid-Every Row has a DDL su ASP.NET 1.0 and 1.1 Basics 0 November 29th, 2006 05:39 PM

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