sri ranjani

sri ranjani

  • 1.8k
  • 81
  • 1.2k

How to populate dropdown list value based on another in edit

Jul 19 2018 3:35 AM
I've 2 dropdowns 1 is site and another is warehouse. Warehouse dropdown value will be changed based on site dropdown.

I done the insert for that dropdowns but when I try to edit the dropdowns already existing value need to be shown and dropdown value should change based on the site edit control..

How could i do the edit for this 2 controls?
I couldn't find a perfect example for this, can anyone help me in this?

What I have tried:

This is my insert template:
<asp:DropDownList ID= "TxtsiteInsert" runat="server" AutoPostBack="True" OnSelectedIndexChanged="sitedropdown_SelectedIndexChanged" TabIndex="6">
<asp:ListItem Text="Select Site"></asp:ListItem>
<asp:DropDownList ID= "TxtWarehouseInsert" runat="server" AutoPostBack="True" TabIndex="7" >
<asp:ListItem Text="Select warehouse"></asp:ListItem>
This is my coding behind that:
Protected Sub sitedropdown_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim IdTxtsiteInsert As DropDownList = CType(DetailsView3.Rows(0).FindControl("TxtsiteInsert"), DropDownList)
End Sub
Public Sub Fillwarehouse(ByVal siteid As String)
'Dim IdTxtWarehouseInsert As DropDownList = CType(DetailsView3.Rows(0).FindControl("TxtWarehouseInsert"), DropDownList)
Dim ddr1 As DropDownList = CType(DetailsView3.Rows(0).FindControl("TxtWarehouseInsert"), DropDownList)
Dim strConn As String = WebConfigurationManager.ConnectionStrings("BMGINC_DYNAX09_ProdConnectionString").ConnectionString
Dim con As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select InventLocationId, Name from InventLocation where dataareaid='BRM' and InventSiteId =@InventSiteId"
cmd.Parameters.AddWithValue("@InventSiteId", siteid)
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
If objDs.Tables(0).Rows.Count > 0 Then
ddr1.DataSource = objDs.Tables(0)
ddr1.DataTextField = "InventLocationId"
ddr1.DataValueField = "InventLocationId"
ddr1.Items.Insert(0, "-Select warehouse-")
ddr1.DataTextField = " "
ddr1.DataValueField = " "
ddr1.Items.Insert(0, " ")
LblError.Text = "No Warehouse found"
End If
End Sub

Answers (2)