Hi..
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"))
Else
toSubSectDDL.DataSource = Office.GetSubSectionsForSection(toSectDDL.Selected Value)
toSubSectDDL.DataTextField = "subsection"
toSubSectDDL.DataValueField = "subSecID"
toSubSectDDL.DataBind()
toSubSectDDL.Items.Insert(0, New ListItem("Select", "0"))
End If
Next
End Sub
and set the ASP code as
<asp:TemplateColumn HeaderText="toSection">
<ItemTemplate>
<asp:DropDownList id="toSectDDL" runat="server" CssClass="standardDDL" Width="402px" OnSelectedIndexChanged="toSectDDL_SelectedIndexCha nged" AutoPostBack="True" ></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
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!!!!!!