Right, but since they are in a detailsview that event isn't available. To access it for adding items, it requires a detailsview.row(0).findcontrol(dropdown1) which is why I am unsure as to how to do this post back update.
Would it be not advisable to just do in a page load under If Page.IsPostBack andAlso detailsview.currentmode=insert?
Right, but since they are in a detailsview that event isn't available. To access it for adding items, it requires a detailsview.row(0).findcontrol(dropdown1) which is why I am unsure as to how to do this post back update.
Oh - so you'll have to do this:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim row As DetailsViewRow = DirectCast(TryCast(sender, Control).Parent.Parent, DetailsViewRow)
Dim DropDownList2 As DropDownList = DirectCast(row.FindControl("DropDownList2"), DropDownList)
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim connectionString As String = ConfigurationManager.ConnectionStrings("yourConnectionString").ConnectionString
conn = New SqlConnection(connectionString)
comm = New SqlCommand("SELECT DataValueField, DataTextField FROM Table", conn)
conn.Open()
reader = comm.ExecuteReader()
DropDownList2.DataSource = reader
DropDownList2.DataValueField = "DataValueField"
DropDownList2.DataTextField = "DataTextField"
DropDownList2.DataBind()
reader.Close()
conn.Close()
End Sub
bluelinenetworks
Would it be not advisable to just do in a page load under If Page.IsPostBack andAlso detailsview.currentmode=insert?
No, because you wouldn't be able to populate the 2nd dropdownlist based on the first one.
Here is what I did...its working for me :D (working with a datasource so no need for all the reader stuff, makes it quite nice!)
The second one builds on the first because it is a post back (autopostback from dropdown1 or dropdown2) and also in detailsviewmode is insert.
Page_Load.....
If Page.IsPostBack AndAlso detailLicense.CurrentMode = DetailsViewMode.Insert Then
updateDetailsViewDropDowns()
End If
Private Sub updateDetailsViewDropDowns()
Dim manDropDown As DropDownList = detailLicense.Rows(0).FindControl("cboManufacturer")
Dim appDropDown As DropDownList = detailLicense.Rows(0).FindControl("cboApplication")
Dim verDropDown As DropDownList = detailLicense.Rows(0).FindControl("cboVersion")
Dim applicationAdapter As New SupportDeskDSTableAdapters.tblLicenseApplicationTableAdapter
Dim applications As SupportDeskDS.tblLicenseApplicationDataTable
applications = applicationAdapter.GetLicenseApplicationByManufacturer(manDropDown.SelectedValue)
Dim applicationList As New List(Of String)
For Each applicationRow As SupportDeskDS.tblLicenseApplicationRow In applications
applicationList.Add(applicationRow.ApplicationName)
Next
appDropDown.DataSource = applicationList
appDropDown.DataBind()
Dim versionAdapter As New SupportDeskDSTableAdapters.tblLicenseVersionTableAdapter
verDropDown.DataTextField = "Version"
verDropDown.DataValueField = "Version"
verDropDown.DataSource = versionAdapter.GetVersionByApplicationName(appDropDown.SelectedValue)
verDropDown.DataBind()
End Sub
Correction to the above post. I had to use request.params("__eventtarget") to determine which dropdown sent the postback.
If postBackControl = "ctl00$cphContent$detailLicense$cboManufacturer" Then
Dim applicationAdapter As New SupportDeskDSTableAdapters.tblLicenseApplicationTableAdapter
Dim applications As SupportDeskDS.tblLicenseApplicationDataTable
applications = applicationAdapter.GetLicenseApplicationByManufacturer(manDropDown.SelectedValue)
Dim applicationList As New List(Of String)
For Each applicationRow As SupportDeskDS.tblLicenseApplicationRow In applications
applicationList.Add(applicationRow.ApplicationName)
Next
appDropDown.DataSource = applicationList
appDropDown.DataBind()
Dim versionAdapter As New SupportDeskDSTableAdapters.tblLicenseVersionTableAdapter
verDropDown.DataTextField = "Version"
verDropDown.DataValueField = "Version"
verDropDown.DataSource = versionAdapter.GetVersionByApplicationName(appDropDown.SelectedValue)
verDropDown.DataBind()
ElseIf postBackControl = "ctl00$cphContent$detailLicense$cboApplication" Then
Dim versionAdapter As New SupportDeskDSTableAdapters.tblLicenseVersionTableAdapter
verDropDown.DataTextField = "Version"
verDropDown.DataValueField = "Version"
verDropDown.DataSource = versionAdapter.GetVersionByApplicationName(appDropDown.SelectedValue)
verDropDown.DataBind()
End If
bluelinenetw...
Member
139 Points
217 Posts
post back from drop down in details view
Feb 14, 2010 11:28 PM|LINK
Hello all,
I have 3 drop downs in a details view (populated from a gridview) during insert mode.
Dropdown 1
Dropdown 2 --> Based on drop down one
Dropdown 3 --> Based on drop down two
I am curious of how to handle the autopostback to update 2 and 3 since they are part of the detailsview, there isn't a selected_index_changed event.
I am ok with adding items to them on page load, just not for cascading of them.....any advice is appreciated :) (and if possible in vb.net)
Web Based Self Service Password Reset for Active Directory Accounts (OpenSource Project)
rivdiv
All-Star
16321 Points
2594 Posts
Re: post back from drop down in details view
Feb 14, 2010 11:44 PM|LINK
You still can use the SelectedIndexChanged event. Make sure you have AutoPostBack="true" and do
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
In the code behind do
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
'Populate 2nd dropdownlist
End Sub
bluelinenetw...
Member
139 Points
217 Posts
Re: post back from drop down in details view
Feb 15, 2010 12:36 AM|LINK
Right, but since they are in a detailsview that event isn't available. To access it for adding items, it requires a detailsview.row(0).findcontrol(dropdown1) which is why I am unsure as to how to do this post back update.
Would it be not advisable to just do in a page load under If Page.IsPostBack andAlso detailsview.currentmode=insert?
Web Based Self Service Password Reset for Active Directory Accounts (OpenSource Project)
rivdiv
All-Star
16321 Points
2594 Posts
Re: post back from drop down in details view
Feb 15, 2010 02:00 AM|LINK
Oh - so you'll have to do this:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Dim row As DetailsViewRow = DirectCast(TryCast(sender, Control).Parent.Parent, DetailsViewRow) Dim DropDownList2 As DropDownList = DirectCast(row.FindControl("DropDownList2"), DropDownList) Dim conn As SqlConnection Dim comm As SqlCommand Dim reader As SqlDataReader Dim connectionString As String = ConfigurationManager.ConnectionStrings("yourConnectionString").ConnectionString conn = New SqlConnection(connectionString) comm = New SqlCommand("SELECT DataValueField, DataTextField FROM Table", conn) conn.Open() reader = comm.ExecuteReader() DropDownList2.DataSource = reader DropDownList2.DataValueField = "DataValueField" DropDownList2.DataTextField = "DataTextField" DropDownList2.DataBind() reader.Close() conn.Close() End SubNo, because you wouldn't be able to populate the 2nd dropdownlist based on the first one.
bluelinenetw...
Member
139 Points
217 Posts
Re: post back from drop down in details view
Feb 15, 2010 07:02 AM|LINK
Here is what I did...its working for me :D (working with a datasource so no need for all the reader stuff, makes it quite nice!)
The second one builds on the first because it is a post back (autopostback from dropdown1 or dropdown2) and also in detailsviewmode is insert.
Page_Load..... If Page.IsPostBack AndAlso detailLicense.CurrentMode = DetailsViewMode.Insert Then updateDetailsViewDropDowns() End If Private Sub updateDetailsViewDropDowns() Dim manDropDown As DropDownList = detailLicense.Rows(0).FindControl("cboManufacturer") Dim appDropDown As DropDownList = detailLicense.Rows(0).FindControl("cboApplication") Dim verDropDown As DropDownList = detailLicense.Rows(0).FindControl("cboVersion") Dim applicationAdapter As New SupportDeskDSTableAdapters.tblLicenseApplicationTableAdapter Dim applications As SupportDeskDS.tblLicenseApplicationDataTable applications = applicationAdapter.GetLicenseApplicationByManufacturer(manDropDown.SelectedValue) Dim applicationList As New List(Of String) For Each applicationRow As SupportDeskDS.tblLicenseApplicationRow In applications applicationList.Add(applicationRow.ApplicationName) Next appDropDown.DataSource = applicationList appDropDown.DataBind() Dim versionAdapter As New SupportDeskDSTableAdapters.tblLicenseVersionTableAdapter verDropDown.DataTextField = "Version" verDropDown.DataValueField = "Version" verDropDown.DataSource = versionAdapter.GetVersionByApplicationName(appDropDown.SelectedValue) verDropDown.DataBind() End SubThanks for your responses though!
Web Based Self Service Password Reset for Active Directory Accounts (OpenSource Project)
bluelinenetw...
Member
139 Points
217 Posts
Re: post back from drop down in details view
Feb 15, 2010 04:31 PM|LINK
Correction to the above post. I had to use request.params("__eventtarget") to determine which dropdown sent the postback.
If postBackControl = "ctl00$cphContent$detailLicense$cboManufacturer" Then Dim applicationAdapter As New SupportDeskDSTableAdapters.tblLicenseApplicationTableAdapter Dim applications As SupportDeskDS.tblLicenseApplicationDataTable applications = applicationAdapter.GetLicenseApplicationByManufacturer(manDropDown.SelectedValue) Dim applicationList As New List(Of String) For Each applicationRow As SupportDeskDS.tblLicenseApplicationRow In applications applicationList.Add(applicationRow.ApplicationName) Next appDropDown.DataSource = applicationList appDropDown.DataBind() Dim versionAdapter As New SupportDeskDSTableAdapters.tblLicenseVersionTableAdapter verDropDown.DataTextField = "Version" verDropDown.DataValueField = "Version" verDropDown.DataSource = versionAdapter.GetVersionByApplicationName(appDropDown.SelectedValue) verDropDown.DataBind() ElseIf postBackControl = "ctl00$cphContent$detailLicense$cboApplication" Then Dim versionAdapter As New SupportDeskDSTableAdapters.tblLicenseVersionTableAdapter verDropDown.DataTextField = "Version" verDropDown.DataValueField = "Version" verDropDown.DataSource = versionAdapter.GetVersionByApplicationName(appDropDown.SelectedValue) verDropDown.DataBind() End IfWeb Based Self Service Password Reset for Active Directory Accounts (OpenSource Project)