在 Web 应用程序中将项目从列表框 1 移动到列表框 2
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案,所以我将其发布在这里。
I figured out the solution so I am posting it in here.
我使用 RadListBox 的 Transferred 事件。当 Transferred 事件触发 Items 时,查看目标列表框的 id 并确定项目是否已移动到未分配或已分配的列表框。一旦知道目的地,您就可以执行查询以在数据库中添加或删除行。
无论如何,您的查询将取决于您的架构。在我的情况下,我有一个查找表来确定该项目是否已附加。
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.