Asp.net自定义控件 带参数

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="News.ascx.cs" Inherits="News" %>
<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
    <li>
    ·<a href="<%# strurl(Eval("isoutlink").ToString(),Eval("pagepath").ToString())%>" class="def" rel="external"><%# GetStrLength(Eval("title").ToString(),14)%></a>
    </li>
    </ItemTemplate> 
</asp:Repeater>
<asp:Label ID="lb_error" runat="server" Visible="False"></asp:Label>

 private string _dispnum = ""; //定义显示条数
    public string dispnum
    {
        get
        {
            return _dispnum;
        }
        set
        {
            _dispnum = value;
        }
    }

    private string _classid = ""; //定义新闻类别ID
    public string classid
    {
        get
        {
            return _classid;
        }
        set
        {
            _classid = value;
        }
    }

    private int _strlen = 1; //定义显示长度
    public int strlen
    {
        get
        {
            return _strlen;
        }
        set
        {
            _strlen = value;
        }
    }
    protected string GetStrLength(string str, int len)
    {
        if (str.Length < this.strlen)
            return str;
        str = str.Substring(0, this.strlen);
        return str;
    }

调用:

<%@ Register Src="UserControl/News.ascx" TagName="News" TagPrefix="uc8" %>

<uc8:News ID="News12" runat="server" dispnum="6" strlen="25" classid="zbgg" />

posted @ 2011-04-02 08:42  洗碗心得  阅读(336)  评论(0编辑  收藏  举报