我尝试使用下面的代码C#SelectedIndex的错误
update_facility_shift_duration.SelectedIndex = Int32.Parse(reader_facility["facility_shift_duration_id"].ToString()); //If this is current user's facility add select
update_facility_shift_duration
对于<selected>
其中由下面的代码获取其值的ID
update_facility_shift_duration.Items.Add(new ListItem(result, reader_facility["facility_shift_duration_id"].ToString()));
我有大约6选择选项和想要选择与数据库中的ID相匹配的那个。
但我收到以下错误。有谁知道如何解决这个问题,或者可能有一些想法将我推向正确的方向? 在此先感谢
您是否有任何方法来验证facility_shift_duration_id的内容?它看起来像试图在reader_facility []中找到不存在的东西 – Floaterz
您是否正在初始化您在'Page_Init'中的项目集合?如果您想在“Page_Load”中使用客户端提供的选定索引,这可能至关重要。 – grek40
请在分配“SelectedIndex”之前检查'update_facility_shift_duration.Items.Count'。确保有足够的物品。 – grek40