[英]Move item from listbox1 to listbox2 in web application
我有2個列表框。 一個包含所有未分配的部門,另一個列表框包含分配給特定人員的所有部門。 現在,我想使用插入和刪除查詢來添加和刪除部門。 該查詢將僅在1個表上執行,即已分配部門(listbox2)並單擊“保存”按鈕。 我已經完成了插入部分,但無法處理刪除部分。 我沒有看到幾個示例,但是它們中沒有DB事件。
protected void Save_Click(object sender, EventArgs e)
{
DataTable dt = GetData2();
bool found = false;
foreach (RadListBoxItem item in RadListBox2.Items)
{
found = false;
foreach (DataRow dr in dt.Rows)
{
if (String.Compare(item.Value, dr["DeptID"].ToString()) == 0)
{
found = true;
label1.Text = "Add a New Group to the ListBox";
}
}
if (found == false)
{
Item(item.Text, item.Value);
}
這就是我想要做的。 我想處理“保存”按鈕上的插入和刪除事件。
我想出了解決方案,所以我將其發布在這里。
foreach (DataRow dr in dt.Rows)
{
found = false;
foreach (RadListBoxItem item in RadListBox2.Items)
{
if (String.Compare(item.Value, dr["DeptID"].ToString()) == 0)
{
found = true;
}
}
if (found == false)
{
//delete here
}
}
}
我使用RadListBox的Transferred事件。 當Transferred事件觸發時,Items將查看目標列表框的ID,並確定是否將這些條目移動到未分配或已分配的ListBox。 一旦知道目的地,就可以執行查詢以從數據庫中添加或刪除行。
無論如何,您的查詢將取決於您的架構。 在我的情況下,我有一個查找表,用於確定該項目是否已附加。
rlistAvailable_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
{
if (e.DestinationListBox.ID == "rlistAttached")
{
foreach (Telerik.Web.UI.RadListBoxItem li in e.Items)
{
//do insert query using li.Value
}
}
else
{
foreach (Telerik.Web.UI.RadListBoxItem li in e.Items)
{
//do delete query using li.Value
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.