我嘗試使用下面的代碼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