首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

GridView上下移动行并把值保存到数据库如何做啊求ing

2013-06-19 
GridView上下移动行并把值保存到数据库怎么做啊!急求ing?GridView上下移动行并把值保存到数据库怎么做啊!

GridView上下移动行并把值保存到数据库怎么做啊!急求ing?
GridView上下移动行并把值保存到数据库怎么做啊!急求ing? 给做个例子100分奉上!小弟新手!多谢了! GridView 数据库 行上下移动
[解决办法]
上下移动是排序还是单行上下的互换?
[解决办法]
Refer:
http://www.cnblogs.com/insus/archive/2013/01/11/2855517.html
[解决办法]
排序的话,如果是Form,有一个AllowUserToOrder属性,Web的话,有一个AllowSorting属性,都是自动排序的
[解决办法]
<style type="text/css">
.style1 {
width: 18%;
}
.style2 {
width: 42%;
}
.mod_piclist .menu {
overflow:hidden;
background-color:#B4A6FF;
font-size:12px;
padding:5px;
height:25px;
}
.mod_piclist .menu ul, .mod_piclist .menu li {
margin:0;
padding:0;
list-style-type:none;
}
.mod_piclist .menu li {
float:left;
width:60px;
height:20px;
text-align:left;
padding-top:5px;
background-repeat:no-repeat;
background-position:center left;
padding-left:20px;
cursor:pointer;
}
.imglist ul, .imglist li {
margin:0;
padding:0;
list-style-type:none;
}
.imglist ul {
border-bottom:1px #999 dotted;
height:25px;
font-size:12px;
cursor:pointer;
}
.imglist li {
float:left;
text-align:left;
margin-left:10px;
padding-top:5px;
}
#lightwindow_container {
border:1px #000 solid;
background-color:#CCC;
}
.selUl {
background-color:#D9D2FB;
}

</style>

            <div class="menu">
              <ul>
                <li style="background-image:url(/sysImages/guestbook/images/url.gif)"><A class="lightwindow page-options" 
  href="/configuration/system/selectImgList.aspx?imgGroupID=<%= imgGroupID %>" 
  params="lightwindow_type=external,lightwindow_width=800,lightwindow_height=400">添加图片</A> </li>
                <li style="background-image:url(/sysImages/guestbook/images/reply.gif)"><A class="lightwindow page-options" 
  href="img_edit.aspx?imgID=0" 
  params="lightwindow_type=external,lightwindow_width=800,lightwindow_height=300" id="a_edit">编辑图片</A></li>
                <li style="background-image:url(/sysImages/guestbook/images/friend.gif)">
                <a href="javascript:SetOrderID()">往上排列</a></li>
                <li style="background-image:url(/sysImages/guestbook/images/del.gif)"><a href="javascript:DeleteImg()">删除图片</a></li>


              </ul>
            </div>
            <div id="list" class="imglist"> 
              <!--
            <ul>
            <li style="width:40px;">1</li>
            <li style="width:400px;">/files/2011-12/QQ截图未命名.jpg</li>
            <li style="width:100px;">24kb</li>
            <li style="width:100px;">200 * 100</li>
            </ul>
            <ul>
            <li style="width:40px;">2</li>
            <li style="width:400px;">/files/2011-12/QQ截图未命名.jpg</li>
            <li style="width:100px;">24kb</li>
            <li style="width:100px;">200 * 100</li>
            </ul>
            <ul>
            <li style="width:40px;">3</li>
            <li style="width:400px;">/files/2011-12/QQ截图未命名.jpg</li>
            <li style="width:100px;">24kb</li>
            <li style="width:100px;">200 * 100</li>
            </ul>
            --> 
            </div>
          </div>
<script>
var _selImgID=0;
var _selImg;
var _isShowImg=true;
var _selRowNum=0;
function setSize(e) {
if (e.width > e.height) {
e.width = e.width > 200 ? 200 : e.width;
}
else {
e.height = e.height > 130 ? 130 : e.height;
}
}
function SetImgList(html)
{

jQuery("#list").html(html);
SetImgListClick();
}
function closelightwindow()
{

document.getElementById("lightwindow_title_bar_close_link").fireEvent("onclick");
//alert(document.getElementById("lightwindow_title_bar_close_link").fireEvent());
}

function GetImgList()
{
var url="/configuration/system/imgGroupOperating.aspx";
var Action ="op=getlist&imgGroupID=<%= imgGroupID %>";
var  options={  
method:'post',  
parameters:Action,  
onComplete:function(transport)


{  
var returnvalue=transport.responseText;
var ary_txt=returnvalue.split("<--Item-->::<--item-->");
if(ary_txt[0]=='true')
{
SetImgList(ary_txt[1]);
}
}
};
   new  Ajax.Request(url,options);
}
function SetImgListClick()
{
var list=document.getElementById("list")
var ul=list.getElementsByTagName("ul");
for(var i=0;i<ul.length;i++)
{

ul[i].onclick=function()
{
var imgid=this.getElementsByTagName("input");
if(imgid.length>0)
{
if(_selImg!=null) _selImg.className="";
_selImgID=imgid[0].value;
this.className="selUl";
_selImg=this;

document.getElementById("a_edit").href="img_edit.aspx?imgID="+ _selImgID;
var li=this.getElementsByTagName("li");
if(li.length>0 && _isShowImg)
{
jQuery("#showImg").html("<img onload="setSize(this)" src=""+ li[1].innerHTML.toLowerCase().replace('{@dirfile}','files') +"" />")
_selRowNum=parseInt(li[0].innerHTML);

}
}
}
}
}
function SetOrderID()
{
if(_selRowNum==0)
{
alert("请先选择一条信息!");
return;
}
if(_selRowNum<=1)
{
alert("信息目前已在最前!");
return;
}

var url="/configuration/system/imgGroupOperating.aspx";
var Action ="op=order&imgGroupID=<%= imgGroupID %>&rownum="+ _selRowNum;
var  options={  
method:'post',  
parameters:Action,  
onComplete:function(transport)
{  
var returnvalue=transport.responseText;
var ary_txt=returnvalue.split("<--Item-->::<--item-->");
if(ary_txt[0]=='true')
{
SetImgList(ary_txt[1]);
var list=document.getElementById("list")
var ul=list.getElementsByTagName("ul");
if(ul.length>0)
{
ul[_selRowNum-2].fireEvent("onclick");
}
}
}
};
   new  Ajax.Request(url,options);

}
function DeleteImg()
{
if(_selRowNum==0)
{
alert("请先选择一条信息!");
return;
}

var url="/configuration/system/imgGroupOperating.aspx";
var Action ="op=del&imgGroupID=<%= imgGroupID %>&imgID="+ _selImgID;
var  options={  
method:'post',  
parameters:Action,  
onComplete:function(transport)
{  
var returnvalue=transport.responseText;
var ary_txt=returnvalue.split("<--Item-->::<--item-->");
if(ary_txt[0]=='true')
{
SetImgList(ary_txt[1]);
var list=document.getElementById("list")
var ul=list.getElementsByTagName("ul");
if(ul.length>0)
{
ul[0].fireEvent("onclick");
}
}
}
};
   new  Ajax.Request(url,options);
}
GetImgList();
</script> 

[解决办法]
        ImgGroupList img = new ImgGroupList();
        ImgGroup imgg = new ImgGroup();
        string retVal = "{0}<--Item-->::<--item-->{1}<--Item-->::<--item-->{2}";



        protected void Page_Load(object sender, EventArgs e)
        {
            string _op = DNTRequest.GetString("op");
            switch (_op)
            {
                case "add":
                    Add();
                    break;
                case "up":
                    break;
                case "del":
                    Delete();
                    break;
                case "order":
                    setOrder();
                    break;
                default:
                    GetList();
                    break;
            }
        }

        private void Add()
        {
            string url = DNTRequest.GetString("url");
            string imgGroupID =Galsun.Common.DNTRequest.GetString("imgGroupID");
            gl_imggroupinfo imggroup = imgg.GetInfoByID(imgGroupID);

            if (imggroup == null 
[解决办法]
 imggroup.id <= 0)
            {
                Response.Write(string.Format(retVal, "false", "选择的组图不存在", ""));
                Response.End();
            }
            if (img.checkImg(url, imgGroupID))
            {
                Response.Write(string.Format(retVal,"false","图片已经存在于当前列表中",""));


                Response.End();
            }
           

            gl_imggrouplistinfo info = new gl_imggrouplistinfo();
            info.imgGroupID = imggroup.imgGroupID;
            info.ImgID = NetCMS.Common.Rand.Number(12);
            info.Url = url;
            info.Creatime = DateTime.Now;
            info.OrderID = 0;
            info.UserName = NetCMS.Global.Current.UserName;
            try
            {
                System.Drawing.Image _image = System.Drawing.Image.FromFile(Server.MapPath(url));
                info.width = _image.Width;
                info.height = _image.Height;
                _image.Dispose();

                FileInfo fi = new FileInfo(Server.MapPath(url));
                info.size = fi.Length;
                string fileEX = System.IO.Path.GetExtension(Server.MapPath(url));
                string _tmpPic = "/files/shortPictures/" + info.Creatime.Year + "-" + info.Creatime.Month + "/" + info.Creatime.Year + info.Creatime.Month + info.Creatime.Day + NetCMS.Common.Rand.Number(5) + fileEX;
                NetCMS.Content.Common.FSImage FSI = new NetCMS.Content.Common.FSImage(200, 132, Server.MapPath(url));
                FSI.Thumbnail(Server.MapPath(_tmpPic));

                info.sUrl = _tmpPic;
            }
            catch
            {

            }


            if (img.Create(info))
            {
                GetList();
            }
            else


            {
                Response.Write(string.Format(retVal, "false", "图片添加失败", ""));
                Response.End();
            }
        }

        private void Delete()
        {
            string imgID = DNTRequest.GetString("imgID");
            img.Delete(imgID);
            GetList();
        }
        private void setOrder()
        {
            string imgGroupID = DNTRequest.GetString("imgGroupID");
            int rownum = DNTRequest.GetInt("rownum", 0);
            gl_imggrouplistinfo info = img.GetInfoByID(rownum, imgGroupID);
            if (info != null && info.id > 0)
            {
                if(info.RowNum>1)
                {
                    gl_imggrouplistinfo info2 = img.GetInfoByID(rownum - 1, imgGroupID);

                    int orderid = info.OrderID;
                    DateTime creatime = info.Creatime;

                    info.OrderID = info2.OrderID;
                    info.Creatime = info2.Creatime;

                    info2.OrderID = orderid;
                    info2.Creatime = creatime;

                    img.Update(info);
                    img.Update(info2);
                    GetList();
                }
            }
        }
        private void GetList()


        {
            string imgGroupID = DNTRequest.GetString("imgGroupID");
            string _list=string.Empty;
            int num = 1;
            foreach (gl_imggrouplistinfo item in img.GetInfoList(imgGroupID))
            {
                _list += "            <ul>\r\n";
                _list += "            <li style="width:40px;">" + item.RowNum + "<input type="hidden" name="imgID" id="imgID" value=""+ item.ImgID + "" /></li>\r\n";
                _list += "            <li style="width:400px;">" + item.Url + "</li>\r\n";
                _list += "            <li style="width:100px;">" + (item.size / 1024).ToString("N2") + "kb</li>\r\n";
                _list += "            <li style="width:100px;">" + item.width + "*" + item.height + "</li>\r\n";
                _list += "            </ul>\r\n";

                num = num + 1;
            }

            Response.Write(string.Format(retVal, "true", _list, ""));
        }
[解决办法]
参考:
http://www.cnblogs.com/insus/archive/2010/12/31/1922815.html

在程序中执行存储过程即可。
[解决办法]
建议你通过JS来吧

热点排行