'ddlXXX' has a SelectedIndex which is invalid because it does not exist in the list of items

'ddlXXX' has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: 'ddlXXX' has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value
Source Error:

Line 269:        ddlxxx.DataTextField = "Name"
Line 270:        ddlxxx.DataValueField = "id"
Line 271:        ddlxxx.DataBind() 
Line 272:        ddlxxx.Items.Insert(0, New ListItem("All", "-1"))
Line 273:        ddlStudents.SelectedIndex = 0

============================

listOrgs.Items.Clear();
listOrgs.SelectedIndex = -1;
listOrgs.SelectedValue = null;
listOrgs.ClearSelection();     // Clears the selection to avoid the exception (only one of these should be enough but in my application I needed all..)
listOrgs.DataSource = new Organization().DTListAll(SiteID);
listOrgs.DataTextField = "OrganizationName"; 
listOrgs.DataValueField = "OrganizationID"; 
listOrgs.DataBind();

posted @   emanlee  阅读(1182)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
历史上的今天:
2009-02-19 C语言程序设计 第二章 数据类型
2009-02-19 C语言程序设计 第一章 C语言简介
2009-02-19 C语言程序设计 概述
2009-02-19 C语言程序设计 使用库函数参考手册
2009-02-19 C语言程序设计 认识函数
2009-02-19 C语言程序设计 VC6调试程序(视频)
2009-02-19 C语言程序设计 C-Free4.1调试程序(视频)
点击右上角即可分享
微信分享提示