获得像 imdb.com 这样的图像的自动完成功能吗?
如何获得类似imdb.com(搜索文本框)的效果? 我正在尝试在自动完成列表中获取图像和电影名称。但是如何使每个 li 可单击或为每个 li 分配 url?
我关注了 此链接< /a>
我写的代码是:
$("#<%=txtsearchmovie.ClientID%>").autocomplete("SearchContents.ashx", {
width:300,
formatItem: function (data, i, n, value) {
return "<img style = 'width:100px;height:100px' src='" + value.split(",")[0] + "'/> " + value.split(",")[1];
},
formatResult: function (data, value) {
return value.split(",")[1];
}
});
在 ashx 中我写了:
public void ProcessRequest(HttpContext context)
{
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["ADO.NET.SqlExpress"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SearchQuery";
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},{2},{3}",
sdr["ThumbNailUrl"], sdr["MovieName"], sdr["MovieId"], sdr["LanguageType"],Environment.NewLine));
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
好的,我尝试了下面的代码。我也用代码更新了我的网站。但我只在图像或文本上获得网址,而不在完整的李上获得网址。 我也无法导航到网址。结果你可以在我的网站上看到。 我想我需要更改js文件的代码。 我在html中使用的代码。
$("#<%=txtsearchmovie.ClientID%>").autocomplete("SearchContents.ashx", {
width: 250,
formatItem: function (data, i, n, value) {
return "<a class='linkbutton' onclick='' href='" + value.split(",")[4] + "'><img class='ac_poster' src='" + value.split(",")[0] + "'/>" + "<div class='ac_moviename'>" + value.split(",")[1] + "</div></a>";
},
formatResult: function (data, value) {
return value.split(",")[1];
}
});
我在 ashx 中写道。
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
string newmovie = Convert.ToString(sdr["MovieName"]).Replace(" ", "-");
string url = "Movies/"+sdr["LanguageType"]+"-Movies/"+sdr["MovieId"]+"/"+newmovie;
sb.Append(string.Format("{0},{1},{2},{3},{4}{5}",
sdr["ThumbNailUrl"], sdr["MovieName"], sdr["MovieId"], sdr["LanguageType"], url,Environment.NewLine));
}
}
这返回我的网址... 如果可能的话请指导我..
How to get effect similar to imdb.com (search textbox).?
i am trying to get image as well as movie name in autocomplete list.but how to make each li as clickable or assign url to each li?
i followed this link
Code i wrote is :
$("#<%=txtsearchmovie.ClientID%>").autocomplete("SearchContents.ashx", {
width:300,
formatItem: function (data, i, n, value) {
return "<img style = 'width:100px;height:100px' src='" + value.split(",")[0] + "'/> " + value.split(",")[1];
},
formatResult: function (data, value) {
return value.split(",")[1];
}
});
and in ashx i wrote:
public void ProcessRequest(HttpContext context)
{
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["ADO.NET.SqlExpress"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SearchQuery";
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},{2},{3}",
sdr["ThumbNailUrl"], sdr["MovieName"], sdr["MovieId"], sdr["LanguageType"],Environment.NewLine));
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
ok i tried below code. as well as i updated my site with the code. but i get url only on image or text but not on full li.
as well as i am not able to navigate to url. Result you can see on my site.
I think i need to change the code of js file.
Code i used in html.
$("#<%=txtsearchmovie.ClientID%>").autocomplete("SearchContents.ashx", {
width: 250,
formatItem: function (data, i, n, value) {
return "<a class='linkbutton' onclick='' href='" + value.split(",")[4] + "'><img class='ac_poster' src='" + value.split(",")[0] + "'/>" + "<div class='ac_moviename'>" + value.split(",")[1] + "</div></a>";
},
formatResult: function (data, value) {
return value.split(",")[1];
}
});
ans in ashx i wrote.
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
string newmovie = Convert.ToString(sdr["MovieName"]).Replace(" ", "-");
string url = "Movies/"+sdr["LanguageType"]+"-Movies/"+sdr["MovieId"]+"/"+newmovie;
sb.Append(string.Format("{0},{1},{2},{3},{4}{5}",
sdr["ThumbNailUrl"], sdr["MovieName"], sdr["MovieId"], sdr["LanguageType"], url,Environment.NewLine));
}
}
this returns my url...
if possible please guide me..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
使用这个 CSS
Try this:
With this CSS