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
// 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;
}
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.
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"
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.
Member
411 Points
1327 Posts
How to change selected column value in selectlistitem
Nov 07, 2019 02:48 PM|polachan|LINK
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
With Many thanks
Pol
Member
180 Points
88 Posts
Re: How to change selected column value in selectlistitem
Nov 08, 2019 07:35 AM|Lewis Lu|LINK
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
Member
411 Points
1327 Posts
Re: How to change selected column value in selectlistitem
Nov 08, 2019 12:37 PM|polachan|LINK
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
All-Star
53131 Points
23682 Posts
Re: How to change selected column value in selectlistitem
Nov 08, 2019 12:59 PM|mgebhard|LINK
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.