Hi micah,
I have created a sample which full fill your requirement please go through the code carefully and implement by modifying the code according to your need and i have saved images in folder with imageName saved in database.
SQL
CREATE TABLE [Users](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](500) NOT NULL,
[Email] [nvarchar](500) NULL,
[UserName] [nvarchar](200) NULL,
[Password] [nvarchar](500) NOT NULL,
[ImageName] [nvarchar](505) NULL)
INSERT INTO Users VALUES('John Hammond','John@gmail.com','John1','John@356','John')
INSERT INTO Users VALUES('Suzanne','Suzanne@gmail.com','Suzanne@2','Suzanne@125','Suzanne')
INSERT INTO Users VALUES('Robert Schidner','Robert@gmail.com','Rob@564','Rob@1478','Robert')
INSERT INTO Users VALUES('Mathews','Mathews@gmail.com','Mathews@415','Math@758','Mathews')
INSERT INTO Users VALUES('Luke','Luke@gmail.com','Luke123','Luke@369','Luke')
INSERT INTO Users VALUES('Lokesh','Lokesh@gmail.com','Lokesh785','Lok@0231','Lokesh')
INSERT INTO Users VALUES('Ronny','Ronny@gmail.com','Ronny2451','Ron3654','Ronny')
HTML
<div>
Search:-
<asp:TextBox ID="txtSearch" runat="server" Width="200"></asp:TextBox>
</div>
<div>
<script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="scripts/jquery.autocomplete.js" type="text/javascript"></script>
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#<%=txtSearch.ClientID%>").autocomplete("Search_CS.ashx", {
width: 200,
formatItem: function (data, i, n, value) {
return "<img style = 'width:50px;height:50px' src='PROFILEPHOTOS/" + value.split("-")[1] + "'/> " + value.split("-")[0];
},
formatResult: function (data, value) {
return value.split("-")[0];
}
});
});
</script>
</div>
Search_CS.ashx
<%@ 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 UserName,ImageName FROM Users WHERE UserName 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(string.Format("{0}-{1}.jpg{2}", sdr["UserName"], sdr["ImageName"], Environment.NewLine));
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Screenshot