`
shirlly
  • 浏览: 1623407 次
  • 性别: Icon_minigender_2
  • 来自: 福州
社区版块
存档分类
最新评论

ListBox之间的数据项的移动操作

    博客分类:
  • .NET
阅读更多
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBoxCommonOperDemo.aspx.cs" Inherits="BusinessDealUserConfig" %>

<%@ Register Src="UCUserInfo.ascx" TagName="UCUserInfo" TagPrefix="uc" %>
<%@ Register Src="UCEmployeeBar.ascx" TagName="UCEmployeeBar" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc:UCUserInfo ID="UCUserInfo" runat="server" />
        <uc:UCEmployeeBar ID="UCEmployeeBar" runat="server" />
        <asp:Label ID="lblTile" runat="server" Text='默认流程配置'></asp:Label>
        <hr />
        <table>
            <tr>
                <td>
                    <asp:DropDownList ID="ddlJobs" runat="server" DataSourceID="odsJobs" DataTextField="JobName"
                        DataValueField="JobCode" AppendDataBoundItems="true" AutoPostBack="true">
                        <asp:ListItem Value="0">-请选择-</asp:ListItem>
                    </asp:DropDownList>
                    <br />
                    <asp:ListBox ID="lstUsers" runat="server" DataSourceID="odsUsers" DataTextField="UserName"
                        DataValueField="UserId" Width="100" Height="100"></asp:ListBox>
                </td>
                <td>
                    <asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" Style="height: 21px" /><br />
                    <asp:Button ID="btnDelete" runat="server" Text="删除" OnClick="btnDelete_Click" />
                </td>
                <td>
                    <asp:ListBox ID="lstDealUsers" runat="server" Width="100" Height="100" DataTextField="DealUserName" DataValueField="DealUserId"></asp:ListBox>
                </td>
                <td>
                    <asp:Button ID="btnUp" runat="server" Text="向上" onclick="btnUp_Click" /><br />
                    <asp:Button ID="btnDown" runat="server" Text="向下" onclick="btnDown_Click" />
                </td>
            </tr>
            <tr>
            <td colspan="4" style="text-align:center">
                <asp:Button ID="btnSave" runat="server" Text="保存" onclick="btnSave_Click" /></td>
            </tr>
        </table>
        <asp:ObjectDataSource ID="odsJobs" runat="server" SelectMethod="GetJobInfos" TypeName="GFOA.Library.UserService">
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="odsUsers" runat="server" SelectMethod="GetEmployeesByJob"
            TypeName="GFOA.Library.UserService">
            <SelectParameters>
                <asp:ControlParameter ControlID="ddlJobs" Name="jobCode" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </div>
    </form>
</body>
</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GFOA.Library;

public partial class BusinessDealUserConfig : System.Web.UI.Page
{
    protected UserService _UserService = new UserService();
    protected DealUserConfigService _DealUserConfigService = new DealUserConfigService(); 

    /// <summary>
    /// 业务ID
    /// </summary>
    public Guid BusinessId
    {
        get
        {
            return new Guid(ViewState["BusinessId"].ToString());
        }
        set
        {
            ViewState["BusinessId"] = value;
        }
    }

    public string BusinessName
    {
        get
        {
            return (string)ViewState["BusinessName"];
        }
        set
        {
            ViewState["BusinessName"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        lblTile.Text = Request["BusinessName"] + "——" + lblTile.Text;
        BusinessId = new Guid(Request["BusinessId"]);
        BusinessName = Request["BusinessName"];
        List<DealUserConfig> dealUserConfigs = this._DealUserConfigService.GetByBusinessId(BusinessId);
        if (dealUserConfigs != null)
        {
            lstDealUsers.DataSource = dealUserConfigs;
            lstDealUsers.DataBind();
        }
    }

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (this.lstUsers.SelectedValue == "")
        {
            ScriptHelper.RegisterScript("alert('没有选中任何用户,请选择用户');window.history.back(-1);");
        }
        else
        {
            lstDealUsers.Items.Add(lstUsers.SelectedItem);
            lstDealUsers.SelectedIndex = 0;
        }
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (this.lstDealUsers.SelectedValue == "")
        {
            ScriptHelper.RegisterScript("alert('没有选中任何用户,请选择用户');window.history.back(-1);");
        }
        else
        {
            lstDealUsers.Items.Remove(lstDealUsers.SelectedItem);
        }
    }

    /// <summary>
    /// 向上
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUp_Click(object sender, EventArgs e)
    {
        if (lstDealUsers.SelectedIndex != 0)
        {
            ListItem tempListItem = lstDealUsers.Items[lstDealUsers.SelectedIndex - 1];

            string text = tempListItem.Text;
            string value = tempListItem.Value;
            lstDealUsers.Items[lstDealUsers.SelectedIndex - 1].Text = lstDealUsers.SelectedItem.Text;
            lstDealUsers.Items[lstDealUsers.SelectedIndex - 1].Value = lstDealUsers.SelectedItem.Value;
            lstDealUsers.Items[lstDealUsers.SelectedIndex].Text = text;
            lstDealUsers.Items[lstDealUsers.SelectedIndex].Value = value;
            lstDealUsers.SelectedIndex = lstDealUsers.SelectedIndex - 1;
            lstDealUsers.DataBind();
        }
        else
        {
            ScriptHelper.RegisterScript("alert('已经到顶了');window.history.back(-1);");
        }
    }

    /// <summary>
    /// 向下
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDown_Click(object sender, EventArgs e)
    {
        if (lstDealUsers.SelectedIndex != lstDealUsers.Items.Count - 1)
        {
            ListItem tempListItem = lstDealUsers.Items[lstDealUsers.SelectedIndex + 1];

            string text = tempListItem.Text;
            string value = tempListItem.Value;

            lstDealUsers.Items[lstDealUsers.SelectedIndex + 1].Text = lstDealUsers.SelectedItem.Text;
            lstDealUsers.Items[lstDealUsers.SelectedIndex + 1].Value = lstDealUsers.SelectedItem.Value;
            lstDealUsers.Items[lstDealUsers.SelectedIndex].Text = text;
            lstDealUsers.Items[lstDealUsers.SelectedIndex].Value = value;
            lstDealUsers.SelectedIndex = lstDealUsers.SelectedIndex + 1;
            lstDealUsers.DataBind();
        }
        else
        {
            ScriptHelper.RegisterScript("alert('已经到底了');window.history.back(-1);");
        }
    }

    /// <summary>
    /// 保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    { 
        this._DealUserConfigService.DeleteByBusinessId(BusinessId);

        List<DealUserConfig> DealUserConfigs = new List<DealUserConfig>();
        int sortIndex =0;
        foreach (ListItem userItem in lstDealUsers.Items)
        {  
            UserInfoProxy userInfoProxy = this._UserService.GetUserInfo(Convert.ToInt32(userItem.Value));
            DealUserConfig dealUserConfig = new DealUserConfig();
            dealUserConfig.Id = Guid.NewGuid();
            dealUserConfig.BusinessId = BusinessId;
            dealUserConfig.DealUserJobCode = userInfoProxy.JobCode;
            dealUserConfig.DealUserJobName = this._UserService.GetJobInfoByCode(userInfoProxy.JobCode).JobName;
            dealUserConfig.DealUserId = Convert.ToInt32(userItem.Value);
            dealUserConfig.DealUserName = userItem.Text;
            dealUserConfig.SortIndex = sortIndex++;

            DealUserConfigs.Add(dealUserConfig);
        }

        this._DealUserConfigService.InsertDealUserConfigs(DealUserConfigs);

        ScriptHelper.MessageDialog("保存成功", "BusinessDealUserConfig.aspx?BusinessName="+BusinessName+"&BusinessId="+BusinessId);
    }
}
分享到:
评论

相关推荐

    在ListBox控件间实现数据交换

    本案例介绍了如何在两个ListBox之间的数据进行交换

    VB在ListBox控件间移动列表项交换数据

    内容索引:VB源码,界面编程,列表 VB在ListBox控件间移动列表项,也就是两个列表项互相交换数据,将选择的列表项从List1移到List2,如果List1中没有选中的列表项则选择第一个列表项,如果List2中没有列表项则退出……...

    VC ListBox左右交换选择数据.rar

    VC ListBox左右交换选择数据,前几年在一些WEB页面中,也经常看到的效果,网页上叫做Select下拉框,也可做成左右双击选择数据,将列表项内容从左边移动到右边,再从右边移除到左边,类似实现数据选择的功能,本例是...

    jquery移动listbox的值原理及代码

    jQuery操作listbox原理并不难,就是将listbox中的选中项进行移动,实现我们需要的移动效果。我在例子中使用了json数据结构来动态绑定listbox,这样也可以熟悉一下json的使用方法。先看看简单的html,因为服务器控件...

    WPF中给listboxItem加上序号标签

    或许有人遇到了这样的问题,开发listbox时想要给它的item加上序号标签,以标识它们各自的位置,但难以实现,大多数人最后只能够在数据源中加入序号数据。但这样又难以实现序号随时更新。如果移动项,往往会出现乱序...

    Delphi开发技巧之-VCL

    移动listbox项目 移动TListView项目 移动TRichEdit内光标到指定位置 聚焦TDBGrid某些单元 自动打开TDateTimePicker 自定义Memo边界 获取TRichEdit中鼠标指针下面的字 访问TRadioGroup的控件 调整TComboBox下拉列表的...

    Delphi开发技巧之-文件操作

    使用API访问ListBox项 使用GetTempFileName创建一个唯一的临时文件 使用INI文件 使用INI文件保存、装载字体信息 使用TFileStream 使用TStream保存字符串 使用TTreeview显示目录 使窗体的关闭按钮失效 修改文本文件 ...

    Visual Basic 6编程技术大全 中译本扫描版带书签 2/2

    16.2.3在应用程序之间传送数据576 16.2.4错误处理581 16.2.5用户接口组件584 16.2.6兼容性问题587 16.2.7注册组件591 16.2.8关闭服务器592 16.2.9 Persistence593 16.3创建ActiveX DLL服务器597 16.3.1 VBIDE中的...

    Visual Basic 6编程技术大全 中译本扫描版带书签 1/2

    16.2.3在应用程序之间传送数据576 16.2.4错误处理581 16.2.5用户接口组件584 16.2.6兼容性问题587 16.2.7注册组件591 16.2.8关闭服务器592 16.2.9 Persistence593 16.3创建ActiveX DLL服务器597 16.3.1 VBIDE中的...

    delphi 开发经验技巧宝典源码

    0218 如何把ADO中的数据导入到ListBox中 145 0219 使用SQL语句保存数据 146 0220 使用赋值方式保存数据 147 0221 当ADO循环删除数据时需要注意的问题 147 0222 把Excel中的数据保存到数据库中 147 0223 ...

    delphi 开发经验技巧宝典源码06

    0218 如何把ADO中的数据导入到ListBox中 145 0219 使用SQL语句保存数据 146 0220 使用赋值方式保存数据 147 0221 当ADO循环删除数据时需要注意的问题 147 0222 把Excel中的数据保存到数据库中 147 0223 ...

    C#程序开发范例宝典2

    83 实例069 在ListView控件中绘制底纹 84 实例070 在列表视图中拖动视图项 85 实例071 用ListView控件选取整行数据 88 实例072 用ListView控件开发登录界面 89 2.8 TreeView控件应用 91...

    C#开发实例大全(基础卷).软件开发技术联盟(带详细书签) PDF 下载

    主要内容有C#开发环境的使用、C#语言基础应用、字符串处理技术、数组和...数据控件、自定义用户控件、文件基本操作、文件夹基本操作、文件流操作、加密、解密及解压缩文件、C#与Word互操作、高效应用Excel、基本图形...

    C#编程经验技巧宝典

    100 &lt;br&gt;0158 如何将二进制数转换为十六进制数 100 &lt;br&gt;0159 如何实现0~9之间随机整数 101 &lt;br&gt;0160 如何实现0~1之间随机数 101 &lt;br&gt;0161 如何返回数字的绝对值 101 &lt;br&gt;5.2 控件数据处理...

Global site tag (gtag.js) - Google Analytics