zoukankan      html  css  js  c++  java
  • 在dreamweaver里如何引用自己写的组件dll里的方法

     

    很多时候在想dreamweaver能否支持自己写的类里的方法,因为它在快速开发上确实很强,但是有很多细节功能却无法实现,比如我要对指定的字符串处理,经常用到的就是网站首页新闻题目列表的显示,超过一行的长度都”…”显示。按照常理来说可以在需要的页里加入一个这样的方法但是如果这样的页很多的话那么每个页都要粘贴一次这个方法,如果有修改的话更是很头疼的问题,这也有悖于面向对象的原则,所以我就想到了把网站开发常用的方法封装到一个类当中然后在相应页中引入这个命名空间,下面给一些代码示例

    首先,我在vs2003下新建一个class项目如下

    using System;

    using System.Data;

    using System.Data.SqlClient;

    using System.Configuration;

     

    namespace aspnetx

    {

           /// <summary>

           /// Summary description for aspnetx.

           /// 这个类主要定义了一些网站开发常用的一些业务逻辑

           /// 利用此类可以简化网站项目的开发,使网站开发节省很多代码编写时间

           /// </summary>

           public class aspnetx

           {

                  ……

                  ……

                  ……

                  /// <summary>

                  /// 按照指定的长度生成文章的题目

                  /// 并且鼠标移动上去可以显示出全名

                  /// </summary>

                  /// <param name="str">指定被处理的字符串</param>

                  /// <param name="length">文章的长度</param>

                  /// <returns></returns>

                  public static string TitleString(string str, int length)

                  {

                         int i = 0, j = 0;

     

                         str=str.Trim();

     

                         string str_s=str;       //传递过来的字符串,显示全名的时候用

     

                         foreach(char chr in str)

                         {

                                if((int)chr > 127)

                                {

                                       i += 2;

                                }

                                else

                                {

                                       i ++;

                                }

                                if (i > length)

                                {

                                       str = str.Substring(0, j) + "......";

                                       break;

                                }

                                j ++;

                         }

                        

                         //加入此html代码使鼠标移动上去显示全名

                         str="<font title='"+str_s+"'>"+str+"</font>";

     

                         return str;

                  }

           }

    }

     

    编译,到bin目录里找到aspnetx.dll,不同的项目可能会生成不同的dll

    拷贝到网站目录的bin文件夹里,然后打开想要引入到的网页中,加入

    <%@ Import Namespace="aspnetx" %>

    各位请根据你们编译的情况修改,引用方法就和简单了,比如:

    <%# aspnetx.TitleString(DataSet1.FieldValue("newstitle", Container),40) %>

     

    如果小项目的话用这种方法我觉得很不错,里面可以加入一些其它的方法

    ---------------------------------------------------------------

    aspnetxBI笔记系列索引:

    使用SQL Server Analysis Services数据挖掘的关联规则实现商品推荐功能

    一起玩转SQL Server 2012 下的分析服务

    使用SQL Server分析服务定位目标用户

    ---------------------------------------------------------------

    来自博客园aspnetx宋卫东

  • 相关阅读:
    基于Python的人脸动漫转换
    let 与 var的区别
    【LeetCode】汇总
    【HDU】4632 Palindrome subsequence(回文子串的个数)
    【算法】均匀的生成圆内的随机点
    【LeetCode】725. Split Linked List in Parts
    【LeetCode】445. Add Two Numbers II
    【LeetCode】437. Path Sum III
    【LeetCode】222. Count Complete Tree Nodes
    【LeetCode】124. Binary Tree Maximum Path Sum
  • 原文地址:https://www.cnblogs.com/aspnetx/p/285314.html
Copyright © 2011-2022 走看看