TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sri ranjani
NA
81
4.1k
How to populate dropdown list value based on another in edit
Jul 19 2018 3:35 AM
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 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)
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
Reply
Answers (
2
)
datatable row to column
Failed to load resource: the server responded with a status