Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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>
                                                                   
                                                                    </InsertItemTemplate>

<InsertItemTemplate>


                                                                      <asp:DropDownList ID= "TxtWarehouseInsert" runat="server" AutoPostBack="True"  TabIndex="7" >
                                                                          <asp:ListItem Text="Select warehouse"></asp:ListItem>
                                                                       </asp:DropDownList>

                                                                   </InsertItemTemplate>


This is my coding:
Protected Sub sitedropdown_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

       Dim IdTxtsiteInsert As DropDownList = CType(DetailsView3.Rows(0).FindControl("TxtsiteInsert"), DropDownList)

       Fillwarehouse(IdTxtsiteInsert.Text)

   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
       con.Open()
       dAdapter.Fill(objDs)
       con.Close()
       If objDs.Tables(0).Rows.Count > 0 Then
           ddr1.DataSource = objDs.Tables(0)
           ddr1.DataTextField = "InventLocationId"
           ddr1.DataValueField = "InventLocationId"
           ddr1.DataBind()
           ddr1.Items.Insert(0, "-Select warehouse-")

       Else
           ddr1.DataTextField = " "
           ddr1.DataValueField = " "
           ddr1.DataBind()
           ddr1.Items.Insert(0, " ")
           LblError.Text = "No Warehouse found"

       End If

   End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900