在 Web 应用程序中将项目从列表框 1 移动到列表框 2

发布于 2024-11-26 21:32:33 字数 772 浏览 4 评论 0原文

我有 2 个列表框。一个列表框包含所有未分配的部门,另一个列表框包含分配给特定人员的所有部门。现在我想使用插入和删除查询添加和删除部门。该查询将仅在 1 个表(即分配的部门(listbox2))上执行,并通过单击“保存”按钮。我已经完成了插入部分,但无法处理删除部分。我见过几个例子,但其中没有数据库事件。

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);
        }

这就是我正在努力做的事情。我想处理“保存”按钮上的插入和删除事件。

I have 2 listboxes. One contains all the department which are unassigned and other listbox contains all the department which is assigned to a particular person. Now I want to add and delete departments using insert and delete query. The query will be performed on 1 table only ie Assigned Department(listbox2) and by clicking the SAVE button. I have done the insert part but unable to handle the delete part. I have seen few examples but they dont have DB event in them.

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);
        }

This is what I am trying to do. I want to handle insert and delete event on Save button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃不饱 2024-12-03 21:32:33

我找到了解决方案,所以我将其发布在这里。

    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
            }
        }


} 

I figured out the solution so I am posting it in here.

    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
            }
        }


} 
相守太难 2024-12-03 21:32:33

我使用 RadListBox 的 Transferred 事件。当 Transferred 事件触发 Items 时,查看目标列表框的 id 并确定项目是否已移动到未分配或已分配的列表框。一旦知道目的地,您就可以执行查询以在数据库中添加或删除行。

无论如何,您的查询将取决于您的架构。在我的情况下,我有一个查找表来确定该项目是否已附加。

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
                }
         }
}

I use the RadListBox's Transferred event. When the Transferred event fires Items look at the destination listbox's id and determine if the items were moved to the unassigned or assigned ListBox. Once you know the destination you can execute a query to add or remove rows from your database.

In any case, your Query will be dependent on your schema. In my situation I had a lookup table that determined if the item was attached.

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
                }
         }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文