• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • ASP實現的一個DataGrid類α版

    發表于:2007-05-25來源:作者:點擊數: 標簽:
    VB SCRIPT'>%@LANGUAGE="VBSCRIPT " % %Option Explicit % \!--#include file="../includes/library.asp"-- \!--#include file="../includes/runtime.asp"-- \!--#include file="../Manager/char.asp"-- \%=lan_getText(session("userLanguage"),0)% script

    <%@LANGUAGE="VBSCRIPT" %>
    <%Option Explicit %>
    <\!--#include file="../includes/library.asp"-->
    <\!--#include file="../includes/runtime.asp"-->
    <\!--#include file="../Manager/char.asp"-->
    <\%=lan_getText(session("userLanguage"),0)%>
    <script>
    function selectAll(obj)
    {
      var top=obj;
      while(true)
      {
         var top=top.parentElement;
      if(top==null)
      {
        break;
      }
      if(top=="undefined")
      {
        top=null;
        break;
      }
      if(top.tagName=="TABLE")
      {
       break;
      }
      }
      var i;
      var j;
      if(top!=null)
      {
        for(i=0;i<top.rows.length;i++)
     {
          for(j=0;j<top.rows[i].cells[0].children.length;j++)
       {
           var temp=top.rows[i].cells[0].children[j];
        if(temp.tagName=="INPUT")
        {
           if(temp.type=="checkbox")
        {
            temp.checked=obj.checked;
        }
        }
       }
     }
      }
    }
    </script>
    <%
    Dim nbdg, errLog
    Set nbdg = new NewsBriefDataGrid
    Dim pageStringTemplate, pageStringTemplate0, pageStringTemplatePrevious0, pageStringTemplateNext0, pageStringTemplatePrevious1, pageStringTemplateNext1


    pageStringTemplate = "<table width=""100%""><tr><td width=""80%"">{0}</td><td>{1}</td></tr></table>"
    pageStringTemplate0         = "合計<font color=""red"">{RowCount}</font>條記錄第<font color=""red"">{CurrentPage}</font>頁/合計<font color=""red"">{PageCount}</font>頁"
    pageStringTemplatePrevious0  = "上一頁&nbsp;"
    pageStringTemplateNext0      = "下一頁&nbsp;"
    pageStringTemplatePrevious1  = "<a href=""?page={Previous}"">上一頁</a>&nbsp;"
    pageStringTemplateNext1      = "<a href=""?page={Next}"">下一頁</a>&nbsp;"


    nbdg.listNewsBriefs Response, pageStringTemplate, pageStringTemplate0, pageStringTemplatePrevious0, pageStringTemplateNext0, pageStringTemplatePrevious1, pageStringTemplateNext1, "page", -1, session("userLanguage"), errLog
    %>


     


     


     



    <%
    Class NewsBriefDataGrid


    '@param Res Response
    '@param newsType 新聞類型
    '@param languageId
    '@errLog
    Public Function listNewsBriefs(Res, pageStringTemplate, pageStringTemplate0, pageStringTemplatePrevious0, pageStringTemplateNext0, pageStringTemplatePrevious1, pageStringTemplateNext1, PAGE_PARAM_NAME, newsType, lang, errLog)
      Dim ret
      Dim currentPage '當前頁碼,從1開始計數
      Dim pageSize '頁大小
      currentPage = Request.QueryString(PAGE_PARAM_NAME)
      If currentPage < 1 Then
        currentPage = 1
      End if
      pageSize = 10
     
      '定義新聞操作句柄
      dim objNews
      set objNews = Server.CreateObject("SanguineRecore.clsNews")
     
      dim count
      objNews.getNewsCount count, -1, "zh_CN", errLog
      ret = ret & (page(pageStringTemplate, pageStringTemplate0, pageStringTemplatePrevious0, pageStringTemplateNext0, pageStringTemplatePrevious1, pageStringTemplateNext1, count, pageSize, PAGE_PARAM_NAME, currentPage))
     
      '獲取新聞并打印
      Dim rows
      Dim isOK
      'isOK = objNews.getNewsBriefs(CInt(startRow), CInt(pageSize), newsType, rows, "0",errLog)
      isOK = objNews.getNewsBriefs ((currentPage - 1) * pageSize, pageSize, newsType, rows, lang, errLog)
      'Res.Write(isOK)
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ' 一個使用數據網格的例子
      ' 下列屬性為必選屬性
      ' DataSource   數據源
      ' RowCount     行數
      ' ColumnCount  列數
      ' Columns      列綁定
      ' HeaderTexts  表頭文本
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      dim dg
      '初始化數據網格
      set dg = new DataGrid
      '設置網格屬性
      dg.tableAttribute = "cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"""
      '設置表格頭屬性
      dg.thAttribute = "bgcolor=""#EEEEEE"" style=""font:normal"""
      '設置表行屬性
      dg.TrAttribute = "onmouseover=""this.style.backgroundColor='#EFEFEF'"" onmouseout=""this.style.backgroundColor='"""
      '設置數據源,為一二維數組
      dg.DataSource = rows
      '設置行數,默認為數據源的行數
      If IsArray(rows) Then
        dg.RowCount = UBound(rows)
      Else
        dg.RowCount = 0
      End if
      '列數,默認為Columns屬性的長度
      dg.ColumnCount = 6
      '設置列綁定
      dg.Columns = array( _
                          "<input type=""checkbox"" name=""id"" value=""{TEXT[0]}"">", _
                          "{TEXT[0]}", _
                          "{HTML[2]}", _
                          "{TEXT[4]}", _
                          "{TEXT[3]}", _
                          "<a href=""edit.asp?id={TEXT[0]}"">編輯</a>"_
                        )
      'Response.Write(rows(0)(1))
      '設置列寬度
      dg.ColumnWidths = array("5%","5%", "20%", "30%", "20%", "")
      '設置列文字對齊方式
      dg.ColumnAligns = array("center", "center", "center", "center", "center", "center")
      '設置表頭文字,支持HTML格式
      '請把下面的漢字修改成類似:lan_getText(languageId,32)
      dg.HeaderTexts = array("<input type=""checkbox"" onclick=""selectAll(this)"">", "ID", "新聞標題", "新聞摘要", "輸入時間", "操作")
      '設置表頭文字對齊屬性,默認對齊方式為center
      dg.HeaderTextAligns = array("center", "center", "center", "center", "center", "center")
     
      ret = ret & dg.ToTable()
      ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      ret = ret & "<input type=""submit"" value=""刪除"">"
     
      ret = ret & "</form>"
      Res.Write(ret)
    '''''''''''''''''''''''''''''' 
    End Function


    '
    '@param rowCount 總行數
    '@param pageSize 每頁顯示的行數
    '@param PAGE_PARAM_NAME page的參數名,用在QueryString中
    '@param currentPage 當前頁碼
    '@return 分頁字符串
    Public Function page(pageStringTemplate, pageStringTemplate0, pageStringTemplatePrevious0, pageStringTemplateNext0, pageStringTemplatePrevious1, pageStringTemplateNext1, rowCount, pageSize, PAGE_PARAM_NAME, currentPage)
      rowCount = CInt(rowCount)
      pageSize = CInt(pageSize)
      currentPage = CInt(currentPage)
      Dim ret
      Dim pageCount, i, tmp
      tmp = rowCount / pageSize
      pageCount = Fix(tmp)
      If(tmp > pageCount) Then
        pageCount = pageCount + 1
      End If
      Dim p1, p2
      p1 = ""
      'p1 = p1 &  "合計<font color=""red"">" & rowCount & "</font>條記錄" _
      '   & "第<font color=""red"">" & currentPage & "</font>頁/" _
      '   & "合計<font color=""red"">" & pageCount & "</font>頁"
      p1 = pageStringTemplate0
      p1 = Replace(p1, "{RowCount}", rowCount)
      p1 = Replace(p1, "{CurrentPage}", currentPage)
      p1 = Replace(p1, "{PageCount}", pageCount)
      ''''''''''
      ''''''''''
     
      if currentPage > 1 then
        'p2 = p2 & "<a href=""?" & PAGE_PARAM_NAME & "=" & (currentPage-1) & """>" & "上一頁" & "</a>&nbsp;"
        p2 = p2 & Replace(pageStringTemplatePrevious1, "{Previous}", currentPage -1)
      else
        'p2 = p2 & "上一頁&nbsp;"
        p2 = p2 & pageStringTemplatePrevious0
      end if
      for i = 1 to pageCount
        if i = currentPage then
          p2 = p2 & i & "&nbsp;"
        else
          p2 = p2 & "<a href=""?" & PAGE_PARAM_NAME & "=" & i & """>" & (i) & "</a>&nbsp;"
        end if
      next
      if currentPage < pageCount then
        'p2 = p2 & "<a href=""?" & PAGE_PARAM_NAME & "=" & (currentPage+1) & """>" & "下一頁" & "</a>&nbsp;"
        p2 = p2 & Replace(pageStringTemplateNext1, "{Next}", currentPage + 1)
      else
        'p2 = p2 & "下一頁&nbsp;"
        p2 = p2 & pageStringTemplateNext0
      end if
      'p = "<table width=""100%""><tr><td width=""80%"">" & p1 & "</td><td>" & p2 & "</td></tr></table>"
      ret = pageStringTemplate
      ret = Replace(ret, "{0}", p1)
      ret = Replace(ret, "{1}", p2)
      page = ret
    End Function


    End Class
    %>


     



    <%
    'Class DataGrid
    '根據給定的列模板和數據源(二維數組)來顯示數據表格
    '
    Class DataGrid
    Private m_dataSource
    '行數
    Private m_rowCount
    '列數
    Private m_columnCount
    Private m_columns
    '表格屬性
    Private m_tableAttribute
    '表頭公共屬性
    Private m_thAttribute
    '表行公共屬性
    Private m_trAttribute
    '單元格屬性
    Private m_tdAttribute
    '列寬
    Private m_columnWidths
    '列對齊格式
    Private m_columnAligns
    '表頭文字
    Private m_headerTexts
    '表頭文字對齊屬性
    Private m_headerTextAligns
    'Private m_rows
    'Private m_r_columns


    Public Property Let DataSource(ds)
      m_dataSource = ds
    End Property


    Public Property Let RowCount(n)
      m_rowCount = n
    End Property


    Public Property Let ColumnCount(n)
      m_columnCount = n
    End Property


    Public Property Let Columns(cols)
      m_columns = cols
    End Property


    Public Property Let TableAttribute(s)
      m_tableAttribute = s
    End Property


    Public Property Let ThAttribute(s)
      m_thAttribute = s
    End Property


    Public Property Let TrAttribute(s)
      m_trAttribute = s
    End Property


    Public Property Let TdAttribute(s)
      m_tdAttribute = s
    End Property


    Public Property Let ColumnWidths(arrayWidth)
      m_columnWidths = arrayWidth
    End Property


    Public Property Let ColumnAligns(aligns)
      m_columnAligns = aligns
    End Property


    Public Property Let HeaderTexts(arrayText)
      m_headerTexts = arrayText
    End Property


    Public Property Let HeaderTextAligns(aligns)
      m_headerTextAligns = aligns
    End Property


    '將二維數組轉換成HTML表格
    '@param rows 二維數組
    '@return HTML表格源碼
    function ToTable()
      dim ret
      ret = ""
      dim row, i, j
      ret = ret & "<table " & m_tableAttribute & ">" & vblf
      ret = ret & "<tr>" & thead() & "</tr>" & vblf
      if IsArray(m_dataSource) then
        for i = 0 to m_rowCount - 1
          row = m_dataSource(i)
          ret = ret & "<tr " & m_trAttribute & ">" & vblf
          for j = 0 to m_columnCount - 1
            ret = ret & "<td " & m_tdAttribute
            If IsArray(m_columnAligns) Then
              ret = ret & " align=""" & m_columnAligns(j) & """"
            End If
             ret = ret & ">" & bind(i, j) & "</td>"
          next
        '
        'ret = ret & "<td " & m_tdAttribute & ">" & "<input type=""checkbox"" name=""id"" value=""" & Server.HTMLEncode(row(m_r_columns(0))) & """>" & "</td>" & vblf
        '
        'for j = 0 to UBound(m_r_columns)
        '  ret = ret & "<td " & m_tdAttribute & ">" & Server.HTMLEncode(row(m_r_columns(j))) & "&nbsp;</td>" & vblf
        'next
        '
        'ret = ret & "<td " & m_tdAttribute & ">" & "<a href=""edit.asp?id=" & Server.HTMLEncode(row(m_r_columns(0))) & """>Edit</a>" & "</td>" & vblf
        '
          ret = ret & "</tr>" & vblf
        next
      end if
      ret = ret & tfoot() & vblf
      ret = ret & "</table>" & vblf
      ToTable = ret
    end function


     Private Function bind(row, col)
       dim format, find, replacement, index, myVarType
       dim openB, closeB
       format = m_columns(col)
       openB = InStr(format, "{")
       dim var
       if openB < 0 then
         bind = format
       else
         closeB = InStr(format, "}")
         var = Mid(format, openB + 1,closeB - openB - 1)
         openB = InStr(var, "[")
         closeB = InStr(var, "]")
         myVarType = Mid(var, 1, openB - 1)
         'Response.Write(myVarType)
         index = CInt(Mid(var, openB+1, closeB - openB -1))
         'Response.Write(index)
         find = "{" & myVarType & "[" & index & "]}"
         If "HTML" = myVarType Then
           replacement = m_dataSource(row)(index)
         ElseIf "TEXT" = myVarType Then
           replacement = Server.HTMLEncode(m_dataSource(row)(index))
         End If
         bind = Replace(format, find, replacement)
       end if
     End Function


    '顯示表頭
    '@param 表頭數組
    '@return 表頭HTML源碼
    private function thead()
      dim ret, i
      ret = ""
      for i = 0 to UBound(m_headerTexts)
        ret = ret & "<th " & m_thAttribute
        If IsArray(m_columnWidths) Then
          ret = ret & " width=""" & m_columnWidths(i) & """"
        End If
        If IsArray(m_headerTextAligns) Then
          ret = ret & " align=""" & m_headerTextAligns(i) & """"
        End if
        ret = ret & ">" & m_headerTexts(i) & "</th>" & vblf
      next
      thead = ret
    end function


    private function tfoot()
    end function


    end Class
    %>

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>