Click here to Skip to main content
15,064,261 members
Please Sign up or sign in to vote.
4.64/5 (6 votes)
Hi,
I have two divs in my view div1 and div 2
div2 is invisible by default
div1 has one link, if user click on that link then div2 should be visible, until then its fine
div1 has a dropdown
HTML
@Html.DropDownListFor(x => x.SelectedRegId, new SelectList(Model.regions, "RegionId", "Name", Model.SelectedRegId), new { @class = "select1", style = "width: 150px;" })


and div2 have another dropdown

HTML
@Html.DropDownListFor(x => x. @Html.DropDownListFor(x => x.SelectedRegIdRpt, new SelectList(Model.regions, "RegionId", "Name", Model.SelectedRegId), new { @class = "select1", style = "width: 150px;" }), new SelectList(Model.regions, "RegionId", "Name", Model.SelectedRegId), new { @class = "select1", style = "width: 150px;" })


Both dropdowns are being populated by Datasource and value-name field coming for them are
1-Central
2-West
3-East

by default both dropdownlist's selected values are Central (First one from database)
I want to set dropdown SelectedRegIdRpt's selected values to be value that is selected in SelectedRegId in div1 before click on link to make div2 visible, I googled a alot but no result, I found this

C#
public SelectList(
    IEnumerable items,
    string dataValueField,
    string dataTextField,
    Object selectedValue
)


but it works on static data, my data is coming from database as I mentioned, any way to accomplish this.
Thanks
Posted
Updated 12-Oct-17 2:24am

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