网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 asp.net实现向上向下排序的例子
内容
    工作中一些常用到的代码记录下来,方便自己查找也方便其他需要人士参考。
    废话不多说,这是一个向上向下排序的功能,首先使用存储过程 整好 如下:
    sql:
    -- =============================================
    -- author:
    -- create date:
    -- description:
    -- =============================================
    alter procedure [dbo].[sp_bannerorder]
    -- add the parameters for the stored procedure here
    (
    @tablename nvarchar(50), --表名
    @colname nvarchar(50), --排序字段
    @keyid nvarchar(50), --表主键字段
    @keyidvalue int, --表主键字段值1
    @order nvarchar(20), -- 列表默认的排序方式,asc或desc
    @orderdirection nvarchar(20), --排序方向,up或down
    @where nvarchar(2000) --查询条件
    )
    as
    begin
    declare @ordertmp1 int; --临时排序值id1
    declare @ordertmp2 int; --临时排序值id2
    declare @tmpkeyidvaule nvarchar(50);
    declare @sql nvarchar(2000);
    declare @parmdefinition nvarchar(500);
    declare @parmdefinition2 nvarchar(500);
    if @order='asc'
    begin
    set @sql = n'select @ordertmp1out='+@colname+' from where as nvarchar(50));
    set @parmdefinition = nvarchar(20) output';
    execute sp_executesql @sql, @parmdefinition, @ordertmp1out=@ordertmp1 output;
    if @orderdirection='up'
    begin
    set @sql = n'select top 1 @ordertmp2out='+@colname+',@tmpkeyidvauleout='+@keyid+' from where as nvarchar(50))+' and order by desc';
    end
    else
    begin
    set @sql = n'select top 1 @ordertmp2out='+@colname+',@tmpkeyidvauleout='+@keyid+' fromwhere as nvarchar(50))+' and order byasc';
    end
    set @parmdefinition = nvarchar(20) output, @tmpkeyidvauleout nvarchar(20) output';
    execute sp_executesql @sql, @parmdefinition, @ordertmp2out=@ordertmp2 output, @tmpkeyidvauleout=@tmpkeyidvaule output;
    end
    else
    begin
    set @sql = n'select @ordertmp1out='+@colname+' from where as nvarchar(50));
    set @parmdefinition =nvarchar(20) output';
    execute sp_executesql @sql, @parmdefinition, @ordertmp1out=@ordertmp1 output;
    if @orderdirection='up'
    begin
    set @sql = n'select top 1 @ordertmp2out='+@colname+',@tmpkeyidvauleout='+@keyid+' from where as nvarchar(50))+' andorder byasc';
    end
    else
    begin
    set @sql = n'select top 1 @ordertmp2out='+@colname+',@tmpkeyidvauleout='+@keyid+' from where as nvarchar(50))+' and order by desc';
    end
    set @parmdefinition = nvarchar(20) output, @tmpkeyidvauleout nvarchar(20) output';
    execute sp_executesql @sql, @parmdefinition, @ordertmp2out=@ordertmp2 output, @tmpkeyidvauleout=@tmpkeyidvaule output;
    end
    set @sql = 'update set as nvarchar(50))+' where as nvarchar(50));
    set @sql = @sql + ' update + ' set as nvarchar(50))+' where as nvarchar(50));
    --select @ordertmp1,@ordertmp2,@tmpkeyidvaule,@sql
    exec(@sql);
    end
    model:
    public class banner
    {
    public banner()
    { }
    private int _id;
    private string _smallpic;
    private string _bigpic;
    private int _orderid;
    private string _url;
    private string _title;
    private string _descript;
    //字增量id
    public int id
    {
    get { return this._id; }
    set { this._id = value; }
    }
    //banner小图
    public string smallpic
    {
    get { return this._smallpic; }
    set { this._smallpic = value; }
    }
    ///
    /// banner大图
    ///
    public string bigpic
    {
    get { return this._bigpic; }
    set { this._bigpic = value; }
    }
    ///
    /// 排序id
    ///
    public int orderid
    {
    get { return this._orderid; }
    set { this._orderid = value; }
    }
    ///
    /// url地址
    ///
    public string url
    {
    get { return this._url; }
    set { this._url = value; }
    }
    ///
    /// 标题
    ///
    public string title
    {
    get { return this._title; }
    set { this._title = value; }
    }
    ///
    /// 描述
    ///
    public string descript
    {
    get { return this._descript; }
    set { this._descript = value; }
    }
    }
    idal代码:
    /// 排序
    ///
    /// 表名
    /// 排序字段
    /// 表主键字段
    /// 表主键字段值
    /// 列表默认的排序方式,asc或desc
    /// 排序方向,up或down
    /// 条件
    ///
    int order(string table,string colname,string keyid,int keyidvalue,string order,string orderdirection,string whe);
    sqldal代码:
    public int order(string table,string colname,string keyid,int keyidvalue,string order,string orderdirection,string whe)
    {
    sqlparameter[] paras = {
    new sqlparameter(@tablename, table),
    new sqlparameter(@colname,colname),
    new sqlparameter(@keyid,keyid),
    new sqlparameter(@keyidvalue,keyidvalue),
    new sqlparameter(@order,order),
    new sqlparameter(@orderdirection,orderdirection),
    new sqlparameter(@where,whe)
    };
    return convert.toint32( sqlhelper.executenonquery(configuration.connectionstring, commandtype.storedprocedure, sp_bannerorder, paras));
    bll代码:
    public int order(string table, string colname, string keyid, int keyidvalue, string order, string orderdirection, string whe)
    {
    return bner.order(table, colname, keyid, keyidvalue, order, orderdirection, whe);
    }
    web:
    aspx代码:
    <%@ page language=c# masterpagefile=~/admin/masterpage/page.master autoeventwireup=true codebehind=banner.aspx.cs inherits=yxshop.web.admin.article.banner %>
    <%@ register assembly=ajaxcontroltoolkit namespace=ajaxcontroltoolkit tagprefix=cc1 %>
    <%@ register assembly=fredck.fckeditorv2 namespace=fredck.fckeditorv2 tagprefix=fckeditorv2 %>
    前台banner管理
    标 题:最多可填写15个字
    描 述:最多可填写20个字
    上传小图:
    errormessage=请选择图片!>
    上传大图:
    errormessage=请选择图片!>
    排 序:
    controltovalidate=txborder errormessage=不能为空!>
    链接地址:
    controltovalidate=txburl errormessage=不能为空!>
    controltovalidate=txburl errormessage=填写的地址不符合规格
    validationexpression=http(s)?://([w-]+.)+[w-]+(/[w- ./?%&=]*)?>
    onclick=btnok_click />
    onrowdatabound=gvwbannner_rowdatabound backcolor=white datakeynames=id
    bordercolor=#e7e7ff borderstyle=none borderwidth=1px cellpadding=3
    gridlines=horizontal onrowcancelingedit=gvwbannner_rowcancelingedit
    onrowdeleting=gvwbannner_rowdeleting onrowediting=gvwbannner_rowediting
    onrowupdating=gvwbannner_rowupdating allowsorting=true width=551px>
    <%--
    dataalternatetextformatstring=这是{0}的图 dataimageurlfield=smallpic
    headertext=图片>
    --%>
    text=向上 onclick=button1_click />
    text=向下 onclick=button2_click />
    commandname=delete text=删除 onclientclick=return confirm('是否刪除?'); >
    cs代码:
    protected void button1_click(object sender, eventargs e)
    {
    int keyidvlue = convert.toint32(gvwbannner.datakeys[((gridviewrow)((button)sender).namingcontainer).rowindex].value); //获取主键值
    int row = convert.toint32(((gridviewrow)((button)sender).namingcontainer).rowindex);//获取行号
    if (row == 0)
    {
    yxshop.common.alert.show(已经最前了!);
    }
    else
    {
    bll.order(banner, orderid, id, keyidvlue, desc, up, 1=1);
    this.bind();
    }
    }
    //向下
    protected void button2_click(object sender, eventargs e)
    {
    //int keyidvlue = ((gridviewrow)((button)sender).namingcontainer).rowindex;
    int keyidvlue = convert.toint32(gvwbannner.datakeys[((gridviewrow)((button)sender).namingcontainer).rowindex].value);
    int row1 = convert.toint32(((gridviewrow)((button)sender).namingcontainer).rowindex);
    if (row1 == this.gvwbannner.rows.count-1)
    {
    yxshop.common.alert.show(已经最后了!);
    }
    else
    {
    bll.order(banner, orderid, id, keyidvlue, desc, down, 1=1);
    this.bind();
    }
    }
    至此完毕。
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/16 17:15:39