如何在C#中获取所选项的索引或ID

如何在C#中获取所选项的索引或ID

本文介绍了如何在C#中获取所选项的索引或ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I wanted to get the Id of the selected item in my List but I don't know how to do it. When the item is selected it turns to IsApplied = true but if not selected it turn to IsApplied = false and save it.





我尝试过:



这是我的代码:





What I have tried:

Here is my code :

public void SetVehicleEquipment(VehicleOptionServiceModel command, MacHaik.Data.IVehicleOption vehicleOption)
        {
            if (command.vOptionEquip != null)
            {
                foreach (var i in command.vOptionEquip)
                {
                    if (i.IsApplied == true) i.IsApplied = true; else i.IsApplied = false;
                }
            }
            if (command.vStandardEquip != null)
            {
                foreach (var c in command.vStandardEquip)
                {
                    foreach (var d in c.Data)
                    {
                        if (d.IsApplied == true) d.IsApplied = true; else d.IsApplied = false;
                    }
                }
            }

            var vopt = _jsonHelper.Serialize(command);
            if (vopt != null)
            {
                var vOption = _vehicleOption.GetVehicleOption(vehicleOption.IVehicleId, vehicleOption.Name);

                if (vOption != null)
                {
                    using (var context = new MacHaikCrmEntities())
                    {
                        vOption.OptionCodes = vopt;
                        context.SaveChanges();
                    }
                }
            }
        }







The problem of the code above is, I havent get the index of the item selected..

推荐答案


这篇关于如何在C#中获取所选项的索引或ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 18:31