Wednesday 15 July 2015

c# - loading dropdown with value -


I have a dropdown that gets data on the fly, I want to show the current selection when the page is loaded and the user Let anyone choose from the list if they want.

All the data related to a site are present on the site and I want to get the current value from the site on my dropdown. The dropdown list is dynamically created by ASPX

  & lt; Tr & gt; & Lt; Td square = "big" & gt; ASP: Dropdown List ID = "Dropmarket" Run = "Server" & gt; & Lt; / Asp: dropdown list & gt; & Lt; / Td> & Lt; / TR & gt; In Aspx.cs  
  Secure Zero Page_load (Object Sender, EventAgds E) {if (! Page.IsPostBack) {market (); Cellsite Utility = New SellSitivity (); Var siteID = Guid.Parse (Request.QueryString ["ID"]. ToString ()); Var site = utility. GatecLite Beide (Site ID); If (site! = Null) {txtsitename.Text = site.SiteName; Txtaddress.Text = site.SiteAddress; Txtzip.Text = site.SiteCityStateZip; Dropmanager.SelectedValue = site.Manager; Dropmarket.SelectedValue = site.Market; }} Private Zero Market () {Sailesite utility utility = New cell site (); Var siteID = Guid.Parse (Request.QueryString ["ID"]. ToString ()); Var market = utility.getMarketsByCellsiteID (Site ID); Foreign exchange (Marketmarket M) {dropmarket.Items.Add (New list item (M. MarketNet.Oustring), M. Market ID.ToString ()); }}   

How can I load site.market at dropmarket when the page is loaded? Thanks in advance.

You can select a list item on page_load:

  ListItem selectedListItem = Dropmarket.Items.FindByValue (site.Market); If (Selected ListItem! = Null) {selectedListItem.Selected = true; };   

or

  dropmarket.SelectedIndex = 0; If (dropmarket.Items.Contains (site.Market)) dropmarket.SelectedIndex = dropmarket.Items.IndexOf (entry); Edit   

:

This example assumes that the site. Price from the market dropdown list is worth. As:

  & lt; Option value = "some value" & gt; Some text & lt; / Options & gt;   

If the site. Use the text from the market dropdown, then use it:

  list item selectedList item = dropmarkatt.imams.findbytext (site.Market);   

Hope it helps!

Conscience

No comments:

Post a Comment