/ Asp.net C# - c#、asp.netのデータベースのエントリによるドロップダウンリストの項目の無効化/無効化

Asp.net C# - c#、asp.netのデータベースのエントリでドロップダウンリストの項目を無効にする

私は、出勤がゲートで記録されるWebアプリケーションを作成しています。ユーザーはStaffIdを持ち、staffIdによって入力されます。

ドロップダウンリストをstaffIdでバインドしていますデータベースに存在します。しかし、ドロップダウンリストのスタッフIDを無効にしたいのですが、その日はすでにチェックインされています。データベースの他のテーブルのエントリに従って、それをデータベースにバインドした後でドロップダウンリストの項目を無効にできますか。

回答:

回答№1は0

こんにちはキラン

DropDownListのプロパティを設定します。

AppendDataBoundItems = "true" DropDownList DataBoundイベントが実行されるようにします。

DropDownListのイベントを設定します。

ondatabound = "DropDownList1_DataBound"

それを実行する

protected void DropDownList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem item in ((DropDownList)sender).Items)
{
string i = item.Value;
//Check the condition from the database whether it is Check in or not
// if check in then find out the value of user e.g userID

if (i == "1")//instead of "1" you pass the User id who checkedIn
{
item.Attributes.Add("style", "color:Green;font-weight:bolder");
item.Attributes.Add("disabled", "disabled");
}
}
}