FineUI 官方论坛
标题:
DropDownList1无法输入内容
[打印本页]
作者:
enactment_str
时间:
2012-3-20 12:06
标题:
DropDownList1无法输入内容
<html xmlns="
http://www.w3.org/1999/xhtml
" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<ext
ageManager ID="
ageManager1" runat="server" />
<ext
anel ID="
anel1" runat="server" Width="500px" >
<Items>
<ext
ropDownList ID="DropDownList1" runat="server" Width="300px"></ext
ropDownList>
</Items>
</ext
anel>
</form>
</body>
</html>
CS
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.Sql;
using System.Data.SqlClient;
namespace rgextaspnet
{
public partial class text : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//extaspnet 实现自动完成autocomplete 下拉功能 .
//页面首次加载时,对下拉框修改,这里改变了下拉框长度,并且添加了一个监听事件keyup,在敲下字符后,触发下拉框查询事件
ExtAspNet.PageContext.RegisterStartupScript
(
"var d=Ext.getCmp('" + DropDownList1.ClientID + "');" +
" var oldInput=\"\";" +
" d.listWidth=500; " +
" d.addListener(\"keyup\",function(f,e){ " +
" var newInput=document.getElementById(\"" + DropDownList1.ClientID + "\").value;" +
" if (oldInput==newInput) {return;} " +
" oldInput=newInput;" +
" __doPostBack('loaddata',newInput);" +
"});"
);
}
else
{
//这里就是keyup触发的事件了,代码是把输入的关键字在数据库里查询,注意在SQL里面,如果数据量大,不要用like来模糊匹配,会慢,用charindex效率要好些
if (Request["__EVENTTARGET"] == "loaddata")
{
SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConne"].ToString());
SqlCommand cmd = new SqlCommand(string.Format("SELECT * FROM FILM where charindex('{0}',id)>0 or charindex('{0}',name)>0",Request["__EVENTARGUMENT"]), Conn);
Conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
DropDownList1.Items.Clear();
while (dr.Read())
{
DropDownList1.Items.Add(new ExtAspNet.ListItem(dr["id"].ToString() + "-" + dr["name"].ToString(), dr["id"].ToString() + DateTime.Now.Ticks.ToString()));//给ddl的value加上时间戳
}
dr.Close();
//下面这句话是有道理的,extjs默认效果在autocomplete之后,值为变成下拉框的第一项,有点破坏效果,这里纠正过来,可以输入多个关键字
ExtAspNet.PageContext.RegisterStartupScript("document.getElementById(\"" + DropDownList1.ClientID + "\").value='" + Request["__EVENTARGUMENT"] + "';");
}
}
}
protected override void Render(HtmlTextWriter writer)
{
string html = "";
StringWriter strWriter = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(strWriter);
base.Render(htw);
html = strWriter.ToString().Replace("id:\"" + DropDownList1.ClientID + "\",", "id:\"" + DropDownList1.ClientID + "\"hideTrigger:true");
html = html.Replace("editable:false", "editable:true");
writer.Write(html);
}
}
}
测试那时DropDownList1无法输入内容
作者:
落末醉
时间:
2012-3-20 14:38
我也在期待 dropdownList 能有更强大的功能
作者:
Landroid
时间:
2012-3-20 18:28
dropdownlist目前还不能input
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4