SharepointTips


Sharepoint Dev And Configuration

Dott. Pasquale Pannuto
(Senior Developer)
TS: Microsoft .NET Framework - Application Development Foundation
MCTS: Microsoft Office SharePoint Server 2007, Configuration
PRO: Designing and Developing Microsoft SharePoint 2010 Applications
TS: SharePoint 2010, Application Development


<script type="text/javascript"><!--
google_ad_client = "ca-pub-7328846173515313";
/* Google */
google_ad_slot = "4019879245";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Autocomplite(jquery) - in sharepoint

Ciao a tutti.

questo post mostra come integrare la funzionalità di autocoplite fruibile mediante l'utilizzo di jquery:

Cosa ci serve:

1 - jquey

Utilizzando un user control (asp.net), la stessa logica può essere applicata a una semplice web part di sharepoint 2007 a una delle nuovissime visual web part presenti nella versione 2010 di Visual studio.

La prima cosa che dobbiamo creare è un handler, che processa le richieste e restituisce un risultato alla pagina ASP.Net:

<%@ WebHandler Language="C#" Class="Search_CS" %>
 
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
 
public class Search_CS : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        string prefixText = context.Request.QueryString["q"];
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager
                    .ConnectionStrings["constr"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select ContactName from Customers where " +
                "ContactName like @SearchText + '%'";
                cmd.Parameters.AddWithValue("@SearchText", prefixText);
                cmd.Connection = conn;
                StringBuilder sb = new StringBuilder();
                conn.Open();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        sb.Append(sdr["ContactName"])
                            .Append(Environment.NewLine);
                    }
                }
                conn.Close();
                context.Response.Write(sb.ToString());
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}

Ora possiamo creare il client:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="scripts/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<%=txtSearch.ClientID%>").autocomplete('Search_CS.ashx');
    });      
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>


N.B.: l'unica accortezza che dobbiamo avere è quella di referenziare correttamente sia i fogli di stile css che i file .js

se tutto è stato fatto nel modo giusto quello che otteniamo è il risultato seguente:


SEMPLICE NO!!!!


Categoria: -
lunedì, 26 lug 2010 Ore. 10.28
Statistiche
  • Views Home Page: -552
  • Views Posts: 56.006
  • Views Gallerie: 2
  • n° Posts: 64
  • n° Commenti: 3
Calendario
aprile 2024
lmmgvsd
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003