locked
How to change selected column value in selectlistitem RRS feed

  • Question

  • User-1355965324 posted

    Hi

    Each user have different depot access right   and they have one of the depot as  his defaultdepot.  I have given  my model and records below .  The UserId 1 has the right to see 1,2,3,4 depot but his defaultdepot is 3. So when the user loggined   and when in the dropdown   one of the depot from the  dropdown can be selected but his default depot would be the depot  having is defaultdepot = true t would be selected in default when the dropdown coming.  But he can  select other depot  from the dropdownlist.  If he  has selected  the depot other than his defaultdepot, the next time the previous selected depot should be the selected value . How can I implement the feature in my function   GetUserDepots

    Depot Model
    DepotNo   Name
    1              asdsadasd 
    2              adadsadsa
    3              adadasdsadkldf
    4              xcnvxmncz
    
    
    UserDepotMapping model
    
    UserID	DepotNo     IsDefaultDepot
    1	1                false
    1	2                false
    1	3                true
    1	4                false
    
    2       2                True 
    2       3                false
    2       4                false
    
    // Here if argument previouslySelectedDepot  has  the value  example  Depot 4, then  that should be the selected Depot  and Selected 
    value of that depot should be true rather than his default depot assigned on the table. Please can you help

    public IEnumerable<SelectListItem> GetUserDepots(int UserID, Int PreviousSelectedDepot) // For Dropdown { IEnumerable<SelectListItem> DepotUserList = (from e in ctx.goUserDepotLink join c in ctx.goDepot on e.DepotNo equals c.DepotNo where e.UserID == UserID select new SelectListItem { Value = c.DepotNo.ToString(), Text = c.DepotName, Selected = e.IsDefault /// Here should be the previous selected DepotNo- PreviousSelectedDepot value }).ToList(); return DepotUserList; }

    With Many thanks

    Pol

    Thursday, November 7, 2019 2:48 PM

All replies

  • User1634355159 posted

    Hi polachan,

    From the logic of your DepotUserList, every time you open a page, the data selected must be the data whose "IsDefault" value is true.If you want to change the default selected value you must change the "IsDefault" value.

    Best Regards,

    Lewis

    Friday, November 8, 2019 7:35 AM
  • User-1355965324 posted

    Please can you advise me how can I change the 'IsDefault' value dynamically. Also if there is no  column "e.isDefault"  physically does not exist in the table , how can we set up "Selected Attributes" 

    With Thanks

    Pol

    Friday, November 8, 2019 12:37 PM
  • User475983607 posted

    Please can you advise me how can I change the 'IsDefault' value dynamically. Also if there is no  column "e.isDefault"  physically does not exist in the table , how can we set up "Selected Attributes" 

    As far as I can tell you are asking the community to solve a design problem without requirements.  It seems to me that you need to write code to persist the select value.   Use an ASP.NET State management feature that fits your needs.  I assume you need to store the select value in a database but your question too vague to answer.

    Friday, November 8, 2019 12:59 PM