zoukankan      html  css  js  c++  java
  • 解决某些.net不方便解决的问题,解决方法就是 DHTML

    using System;
    using System.Collections;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace PPA.Runtime.Util
    {
     /// <summary>
     /// WebUtil Web功能。
     /// </summary>
     public class WebUtil
     {
      public WebUtil()
      {
       //
       // TODO: 在此处添加构造函数逻辑
       //
      }
      public static void InsertTableColumn(Page page, string tabObjId, int columnIdx, string innerHTML, int width)
      {
       StringBuilder script = new StringBuilder();
       script.Append("<script language=javascript> \n<!--\n");
       script.Append("function InsertColumn(tab,idx,tdContent,tdWidth) \n");
       script.Append("{ \n");
       script.Append("var td = tab.rows[0].insertCell(idx); \n");
       script.Append("td.rowSpan = tab.rows.length; \n");
       script.Append("td.innerHTML = tdContent; \n");
       script.Append("td.width = tdWidth; \n");
       script.Append("} \n-->\n</script>\n");
       page.RegisterStartupScript("InsertColumnScript",script.ToString());

       StringBuilder call = new StringBuilder();
       call.Append("<script language=javascript> \n<!--\n");
       call.AppendFormat("InsertColumn(document.all[\"{0}\"],{1},\"{2}\",{3});",tabObjId,columnIdx,innerHTML,width);
       call.Append(" \n-->\n</script>\n");
       page.RegisterStartupScript("CallInsertColumnScript",call.ToString());
               
      }
      public static void ScrollIntoObject(Page page,string objId)
      {
       StringBuilder script = new StringBuilder();
       script.Append( "<script language=\"javascript\">\n");
        script.Append( "function ViewObj(objName)\n");
        script.Append( "{\n");
        script.Append( "var obj = document.all.item(objName);\n");
        script.Append( "if (obj != null)\n");
        script.Append( "{\n");
        script.Append( "\tobj.scrollIntoView();\n");
       script.Append( "\twindow.scroll(0,window.screen.availHeight/3);\n");
        script.Append( "\tobj.focus();\n");
        script.Append( "}\n");
        script.Append( "}\n");
       script.Append( "function AutoScrollIntoView()"); 
        script.Append( "{\n");
        script.Append( string.Format("setTimeout(\"ViewObj('{0}')\",1000);\n", objId));
        script.Append( "}\n");
        script.Append( "window.onload = AutoScrollIntoView;\n");
        script.Append( "</script>\n");    
       page.RegisterStartupScript("AutoScrollIntoView",script.ToString());   
      }
      /// <summary>
      /// 合并指定数据表的某些列,条件是相邻上下列的内容一致
      /// </summary>
      /// <param name="grid">数据表</param>
      /// <param name="startRow">开始计划合并的行</param>
      /// <param name="cellIdx">第几列要计划合并</param>
      public static void MergeDataGridCells(DataGrid grid,int startRow,int cellIdx)
      {
       StringBuilder script = new StringBuilder();
       script.Append("<SCRIPT LANGUAGE=\"JScript\">\n");
       script.Append("function mergeCells(tab,startRow,cellIdx) {\n");
       script.Append(" var lastCell = null;\n");
       script.Append(" for (var i=startRow; i < tab.rows.length; i++) {\n");
       script.Append("  var row = tab.rows(i);\n");
       script.Append("  var cell = row.cells(cellIdx);\n");     
       script.Append("  if(lastCell != null)\n");
       script.Append("  {   \n");
       script.Append("   if(lastCell.innerHTML == cell.innerHTML)\n");
       script.Append("   {\n");
       script.Append("    row.deleteCell(cellIdx);\n");
       script.Append("    lastCell.rowSpan ++;\n");
       script.Append("   }\n");
       script.Append("   else\n");
       script.Append("    lastCell = cell;  \n");
       script.Append("  }\n");
       script.Append("  else\n");
       script.Append("   lastCell = cell;\n");
       script.Append(" }\n");
       script.Append("}\n");
       script.Append("</SCRIPT>\n");   
       grid.Page.RegisterStartupScript("MergeTableCellScript",script.ToString());
       //DO IT!!!
       StringBuilder doScript = new StringBuilder();   
       doScript.AppendFormat("<script language=javascript><!--\n mergeCells({0},{1},{2});\n-->\n</script>",grid.ID,startRow,cellIdx);
       grid.Page.RegisterStartupScript("DoMerge" + grid.ID + "cells",doScript.ToString());
      }
      
      /// <summary>
      /// 取得选中的编号列表
      /// </summary>
      /// <param name="dataGrid">数据表</param>
      /// <param name="checkBoxList">checkbox的id</param>
      /// <param name="labelId">存放编号的label的id</param>
      /// <returns></returns>
      public static IList GetSelectedIdList(DataGrid dataGrid,string checkBoxList,string labelId)
      {
       IList result = new ArrayList();
       for (int i = 0; i < dataGrid.Items.Count; i++)
       {
        CheckBox chkBox = (CheckBox) dataGrid.Items[i].FindControl(checkBoxList);
        if (chkBox.Checked)
        {
         Label LabelId = (Label) dataGrid.Items[i].FindControl(labelId);
         result.Add(Convert.ToInt32(LabelId.Text));
        }
       }
       return result;
      }
     }
    }

  • 相关阅读:
    IE表单拦截器
    使用网站作为WCF服务宿主的几种做法
    Javascript执行效率小结
    Ajax无刷新技术实现省市县三级联动下拉菜单Asp.Net
    序列化DataContractSerializer
    变化多端的列表
    腾讯微信
    Mac OS 和 iOS 操作系统架构
    程序员远离你的细节思维
    ObjectiveC概述
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/169189.html
Copyright © 2011-2022 走看看