BlankLink:空白链接的实现代码效果

2017-06-15 09:12:27  访问(2213) 赞(0) 踩(0)

  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BlankLink.aspx.cs" Inherits="BlankLink" ValidateRequest="false" EnableViewState="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <link href="~/css/HrefItem.css" rel="stylesheet" type="text/css" />
        <link href="~/css/font14.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            名称:<asp:TextBox runat="server" ID="txt_KW" Width="300px"></asp:TextBox>
            <asp:Button ID="btn_Search" runat="server" OnClick="btn_Search_Click" OnClientClick="JsSearchClick(); return false; "  Text="搜索" /><br /><br />
            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <a class="DefaultHref" href="<%#ConvertToUrl(Eval(_LinkUrl)) %>"
                        target="_blank"><%#(Container.ItemIndex+1)%>、<%#Eval("TheName") %></a>
                    <br /><br />
                </ItemTemplate>
            </asp:Repeater>
             
        </div>
        </form>
    </body>
    </html>
    <script language="javascript" type="text/javascript">
    
        function JsSearchClick() {
            var kw = document.getElementById("txt_KW").value;
    
            window.location.href = "blanklink.aspx?kw=" + escape(kw);
    
            return false;
        }
    </script>
    

  • 
        /// <summary>
        /// 友情链接
        /// </summary>
        /// <param name="xdbHelper"></param>
        /// <returns></returns>
        public List<BaseModel> FriendLinkList
            (
                DBHelper xdbHelper
            )
        {
            return FriendLinkList("","", xdbHelper);
        }
    
        /// <summary>
        /// 友情链接
        /// </summary>
        /// <param name="theCode"></param>
        /// <param name="kw"></param>
        /// <param name="xdbHelper"></param>
        /// <returns></returns>
        public List<BaseModel> FriendLinkList
            (
                string theCode,
                string kw,
                DBHelper xdbHelper
            )
        {
            List<BaseModel> theResult = null;
    
            bool bIsCreate = true;
    
            if (xdbHelper == null)
            {
                xdbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
            }
            else
            {
                // 没有打开链接 //
                bIsCreate = xdbHelper.IsNotOpen();
            }
    
            try
            {
                if (bIsCreate)
                    xdbHelper.OpenDBHelper();
    
                SlowX.NewsLib.Business.UTB_SLOWX_LINK
                    bll 
                    = 
                    SlowX.NewsLib.Business.UTB_SLOWX_LINK.instance;
    
                if (theCode == null || theCode.Length == 0)
                {
                    theCode = "友情链接";
                }
    
    
                theResult = bll.GetList8TheCode(theCode, kw, xdbHelper);
    
                if (bIsCreate)
                    xdbHelper.EndDBHelper();
    
            }
            catch (Exception err)
            {
                if (bIsCreate)
                    xdbHelper.TranDBHelper();
    
                throw err;
            }
            finally
            {
                if (bIsCreate)
                    xdbHelper.FinallyDBHelper();
            }
    
            return theResult;
        }
    
  • using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using SlowX.WebSite.Classes;
    using SlowX.WebSite.Common;
    using SlowX.Core.Model;
    using SlowX.DAL.Helpers;
    
    public partial class BlankLink 
        :
        System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        public string phyPath
        {
            get
            {
                return WebBasicData.instance.phyPath;
            }
        }
    
        protected string _LinkUrl
        {
            get
            {
                return "LinkUrl";
            }
        }
    
        /// <summary>
        /// 转换"成&quot;
        /// 如:canoe"best,结果为canoe&quot;best
        /// </summary>
        /// <param name="obj">传入的字符串(canoe"best)</param>
        /// <returns>输出的结果,如(canoe&quot;best)</returns>
        public string StringConvertQuot(string obj)
        {
            if (obj == null)
                return string.Empty;
    
            return obj.Replace("\"", "&quot;");
        }
    
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected string ConvertToUrl(object obj)
        {
            if (obj == null)
                return "";
    
            string str = obj.ToString();
            if (str.StartsWith("~/"))
                return StringConvertQuot(phyPath + str.Substring(1));
    
            return StringConvertQuot(str);
        }
    
    
        /// <summary>
        /// 友情链接绑定
        /// </summary>
        protected void FriendLinkDataBind(DBHelper xdbHelper)
        {
    
            string kw = Request.QueryString["kw"];
    
            if (kw == null)
                kw = "";
            else
                kw = Server.UrlDecode(kw).Trim();
    
            txt_KW.Text = kw;
    
            WebSiteBLL wi = WebSiteBLL.instance;
    
            List<BaseModel> theList
                =
                wi.FriendLinkList("常用链接", kw, xdbHelper);
    
            if (theList == null || theList.Count == 0)
            {
                return;
            }
    
            Repeater1.DataSource = theList;
            Repeater1.DataBind();
    
    
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            if (txt_KW.Text.Trim().Length == 0)
            {
                Response.Redirect("BlankLink.aspx");
                return;
            }
    
            Response.Redirect("BlankLink.aspx?kw=" + Server.UrlEncode(txt_KW.Text.Trim()));
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                FriendLinkDataBind(null);
            }
            catch (Exception err)
            {
                Response.Write(err.Message);
            }
        }
    }
    
    

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)