asp.net 模糊查询(传入第三个参数)
html页
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" ServicePath="~/DataService.asmx" MinimumPrefixLength="1" CompletionInterval="500" EnableCaching="true" TargetControlID="txtChannel" ServiceMethod="GetChannel" FirstRowSelected="True" CompletionListElementID="listPlacement" CompletionListCssClass="ajxstyle"> </ajaxToolkit:AutoCompleteExtender> <div id="listPlacement" runat="server" style="height: 350px; overflow: auto; display: none;" /> 渠道模糊查询: <asp:TextBox ID="txtChannel" runat="server" Width="350px" ToolTip="输入进行模糊查询" OnTextChanged="txtChannel_TextChanged" onkeydown="return OnTxtKeyDown();" AutoPostBack="True" />
js获取并设置第三个参数:
//AutoCompleteExtender传递第三个参数
function OnTxtKeyDown() {
var acNameClientId = "<%=AutoCompleteExtender2.BehaviorID %>";
var acName = $find(acNameClientId);
if (acName != null) {
var orderID = $("select[id*='DrpOrder']").val();
if (!isNaN(orderID)) {
acName.set_contextKey(orderID);
}
}
}
后台方法,文本框内容改变时:
protected void txtChannel_TextChanged(object sender, EventArgs e)
{
try
{
string selectValue = txtChannel.Text.ToString();
if (!string.IsNullOrEmpty(selectValue))
{
string chanId= selectValue.Substring(selectValue.LastIndexOf('[')+1, selectValue.Length-selectValue.LastIndexOf('[')-2);
DrpChannel.SelectedValue = chanId;
drpChannelChan();
}
}
catch
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "s", "alert('未在本订单查到["+txtChannel.Text.Trim()+"]!');", true);
}
}
webService的方法,其中contextKey为第三个参数
[System.Web.Script.Services.ScriptMethod]
[WebMethod]
public string[] GetChannel(string prefixText, int count, string contextKey)
{
if (!string.IsNullOrEmpty(contextKey))
{
string sql = string.Format(@"
SELECT CHANNEL_NAME FROM (
SELECT
'(' || C.QX_CHANNEL_NAME || ')' || C.NAME ||'['||C.ID||']' CHANNEL_NAME
FROM TL_REQUISITION A, TL_USER_INFO B, V_CHANNEL_PATH C
WHERE A.ORDER_ID = {0}
AND A.USER_ID = B.ID
AND B.CHANNEL_ID = C.ID
AND (A.STATUS <> '草稿' AND A.STATUS NOT LIKE '%退回%')
AND (A.IS_SCAN IS NULL OR A.IS_SCAN = 0)
ORDER BY C.QX_CHANNEL_NAME
)WHERE CHANNEL_NAME LIKE '%{1}%'", Convert.ToInt32(contextKey), prefixText);
ISqlQuery isqlQuery = AppHelper.GetService<ISqlQuery>();
isqlQuery.Sql = sql;
DataTable dt = isqlQuery.Execute();
string[] strArray = null;
if (dt != null)
{
if (dt.Rows.Count > 0)
{
List<String> list = new List<String>();
foreach (DataRow item in dt.Rows)
{
list.Add(item[0].ToString());
}
strArray = list.ToArray();
}
}
return strArray;
}
else return null;
}
浙公网安备 33010602011771号