ASP实现的一个DataGrid类α版[3]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 redv 的 blog

      p2 = p2 & i & " "
    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

本文关键:ASP实现的一个DataGrid类α版
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top