用JavaScript对GridView进行上、下移动,并保存排序

  < script type = " text/javascript "  language = " javascript " >
        
// 移动排序
        function Move(part)
        
{
          var count
= document.getElementById('HidCount').value;
          var temp
=0;
          var index
=0;
          var indexid
=0
          
for( i=0 ;i<=count;i++)
          
{
            var bc
=document.getElementById('GVLesson_Row_'+i).style.backgroundColor;
             
if(bc=='#f8e0e0')
            

                index
=document.getElementById('GVLesson_Row_'+i).rowIndex;
                indexid
=i;
                
//alert("GoUp  "+index);
                temp=temp+1;
            }
          
          }

          
if(temp<0||temp>1)
          
{
            alert(
"只能选择一节课程!");
            
return;
          }

          
//上移
          if(part=='U')
          
{  
              
if(index==1)
              
{
                alert(
"第一行无法上移!");
                
return;
              }
         
              GVLesson.rows[index
-1].swapNode(GVLesson.rows[index]);          
               
for(obj in GVLesson.rows[index-1].cells[0].children)
               
{
                   document.form1.elements[obj].
checked='checked';
               }

               
//得到单一列的索引
//               var tempaa=GVLesson.rows[index-1].cells[2];
//         
//                alert(tempaa.innerHTML)
//                for(i=0;i<tempaa.childNodes.length;i++)
//                {
//                     if(tempaa.childNodes[i].tagName=="INPUT")
//                     {
//                        alert(tempaa.childNodes[i].value);
//                        alert(document.getElementById('GVLesson_Row_'+tempaa.childNodes[i].value+'_Hid_index').value);
//                     }                
//                }
//              
          }

          
else//下移
          {
              
if(index-1 == count)
              
{
                alert(
"最后一行无法下移!");
                
return;
              }

              GVLesson.rows[index
+1].swapNode(GVLesson.rows[index]);
              
for(obj in GVLesson.rows[index+1].cells[0].children)
              
{
                   document.form1.elements[obj].
checked='checked';
              }

          }
    
        }

        var indexID
= "" ;
        var indexValue
= "" ;
        
// 保存排序
        function saveTaxis()
        
{
            var indexcount
=GVLesson.rows.length;//表总行数
            
//alert(indexcount);
            for(i=1;i<indexcount;i++)//客户端课程表
            {
                var tempaa
=GVLesson.rows[i].cells[2];
                indexID 
= indexID + i + ",";
                
//alert(tempaa.innerHTML)
                for(t=0;t<tempaa.childNodes.length;t++)
                
{
                     
if(tempaa.childNodes[t].tagName=="INPUT")
                     
{
                      
//alert(tempaa.childNodes[t ].value);//得到隐藏域的值
                      indexValue = indexValue + tempaa.childNodes[t ].value + ",";
                     }
                
                }

            }

            
//alert(indexID);
            
//alert(indexValue);
            AjaxRequestobj();
        }

        
// 使用Ajax保存排序。
        function AjaxRequestobj()
        
{
            alert(indexID);
            alert(indexValue);
            var code
="";
            var http_request 
= false;     
            
if (window.XMLHttpRequest) // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            
if (http_request.overrideMimeType) {
                http_request.overrideMimeType(
'text/xml');
            }

            }
 else if (window.ActiveXObject) // IE
                try {
                    http_request 
= new ActiveXObject("Msxml2.XMLHTTP");
                }
 catch (e) {
                    
try {
                        http_request 
= new ActiveXObject("Microsoft.XMLHTTP");
                    }
 catch (e) {}
                }

            }

            
if (!http_request) {
                alert(
'Giving up :( Cannot create an XMLHTTP instance');
                
return false;
            }

            
else
            
{
                http_request.open(
"GET","TeacherLesson.aspx?ID=" + indexID + "&VL=" + indexValue,true);
                http_request.send();
                
if (http_request.readyState == 4)
                
{
                   
if (http_request.status == 200)
                   
{
                        alert(http_request.responseText);
                        code
=http_request.responseText;
                       
                        
if(code=="1")
                            window.location.reload();
                        
else
                            alert(
"操作失败请重试!");
                    }

                    
else
                        window.location.reload();
                }

                
else
                    window.location.reload();   
            }

        }

</ script >        

后台代码:
private   void  AjaxRequest()
    
{
        
string ID = Request["ID"].ToString();
        
string VL = Request["VL"].ToString();
        
string[] IndexID = ID.Split(',');
        
string[] IndexValue = VL.Split(',');
        
bool test = true;
        
for (int i = 1; i < IndexID.Length; i++)
        
{
            
if (!new FCD_Lesson().Updata_LessonTaxis(Convert.ToInt32(IndexValue[i - 1].ToString()), Convert.ToInt32(IndexID[i - 1].ToString())))
            
{
                test 
= false;
                
break;
            }

        }

        
if(test)
            Response.Write(
"1");
        
else
            Response.Write(
"0");
        Response.Flush();
        Response.End();
    }
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值