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
cmdCauseDetails.Parameters.Add(prmCauseDetail)
Dim dtrDetails As SqlDataReader
Try
connFF.Open()
dtrDetails = cmdCauseDetails.ExecuteReader
ddlCauseDetails.DataSource = dtrDetails
ddlCauseDetails.DataTextField = "Details"
ddlCauseDetails.DataValueField = "Details"
ddlCauseDetails.DataBind()
dtrDetails.Close()
connFF.Close()
Catch er As Exception
LogError(er.ToString, "CauseDetails-Incident.aspx")
Exit Try
Finally
connFF.Close()
End Try
End Sub
Sub dlIncident_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dlIncident.SelectedIndexChanged
Dim ddlCausedetails As DropDownList
BindCauseDetails(ddlCausedetails)
End Sub
<asp:DropDownList id="ddlcausetype" runat="server" OnSelectedIndexChanged="dlIncident_SelectedIndexCh anged"
Width="272px" ForeColor="Gray" AutoPostBack="True"></asp:DropDownList></TD>
|