Last post Jan 26, 2020 03:24 PM by TRIMS30
Jan 24, 2020 07:05 PM|TRIMS30|LINK
I have two Drop Down Lists - One for PROJECTS and one for ACTIVITIES
Each PROJECT has a unique set of ACTIVITIES
My PROJECT data contains the following Descriptions and Values:
Dropdown List displays Descr Items and Code items are selectedValues
Park Maintenance, PAR
Street Maintenance, STR
Building Mantenance, BLD
ACTIVITY Data Has Descr, Act and Proj fields
Dropdown List displays Descr Items and Act items are selectedValues - Proj field is used for filtering
Descr, Act, Proj
Mowing, 1, PAR
Sweep, 1, STR
Repair, 2, STR
Paint, 1, BLD
Windows, 2, BLD
When I select a PROJECT I want only those ACTIVITIES related to that PROJECT loaded int the ACTIVITY DropDownList.
Im using Xpath to accomplish this.
Here's code I'm Using.
Private Sub lstProject_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstProject.SelectedIndexChanged
xmlActivities.DataFile = Server.MapPath("~\data\TRIMS_Net\") & Session("Serial") & "\Activities.xml"
xmlActivities.XPath = "/Activity_List/Activity[ @Proj='" & sender.selectedvalue & "']"
lstActivity.DataBind() 'Bind to Activity List
lstActivity.Selectedindex = -1
This works fine the 1st time I select a project - correct activities are loaded into Activity List.
Selecting a different Project causes its Activities to be appended to Existing Activities in Activity DropDown List
How do I get only currently selected Data via Xpath to be in Activity List?
Any help is appreciated.
Jan 26, 2020 06:35 AM|KathyW|LINK
Does your dropdownlist have AppendDataBoundItems="true"?
Jan 26, 2020 03:03 PM|KathyW|LINK
It's common to set a dropdownlist to AppendDataBoundItems="true" if you want to hard code a first option of "Select", or something similar. This works untll you rebind the dropdownlist again, at which point it appends the new items after the existing ones.
You either have to clear the list before you rebind it, and insert the Select again, or just let AppendDataBoundItems="false" and always insert the "Select" list item in position 0 of the DDL after databinding.
Jan 26, 2020 03:24 PM|TRIMS30|LINK
Found Problem. I was binding XML Control on every postback.
All OK Now.