• 解决某些.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;
      }
     }
    }

  • 相关阅读:
    POJ1064 Cable master(二分 浮点误差)
    Codeforces1113F. Sasha and Interesting Fact from Graph Theory(组合数学 计数 广义Cayley定理)
    Codeforces1100F. Ivan and Burgers(离线+线性基)
    Codeforces1097D. Makoto and a Blackboard(数论+dp+概率期望)
    Codeforces1099F. Cookies(线段树+dp+贪心+博弈)
    python-zx笔记4-文件操作
    python-zx笔记3-函数
    python-zx笔记2-help
    fiddler使用笔记1
    理解OAuth 2.0
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/169189.html
Copyright © 2020-2023  润新知