[研究]DropDownList從資料庫抓出的值,不在下拉選項中的處理
2025-04-01
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19
DropDownListClass.cs
using System;
using System.Web.UI.WebControls;
namespace WebApplicationProject1.Controls
{
public class DropDownListClass : DropDownList
{
protected override void PerformDataBinding(System.Collections.IEnumerable dataSource)
{
// 過濾掉 DropDownList 在 DataBinding 時可能會發生的 Exception 問題!
// 如果 Exception 發生,預設會選取第一個下拉選項!
try
{
base.PerformDataBinding(dataSource);
}
catch (ArgumentOutOfRangeException ex)
{
ArgumentOutOfRangeException o = ex;
}
}
}
}
|
(完)
相關

沒有留言:
張貼留言