前台 aspx 页面
<ul class="nav nav-pills" style="float:left;margin-right:10px;">
<li class="dropdown active">
<a class="dropdown-toggle" data-toggle="dropdown"href="#">
<span id="span_ListName">请选择</span>
<input id="txtListCode" type="text" value="" style="display:none;"/>
<b class="caret"></b>
</a>
<ul id="ul_List" class="dropdown-menu">
<li><a href='javascript:void(0);' οnclick="List_Click('All','全部订单');\">全部订单</a></li>
<li class="divider"></li>
</ul>
</li></ul>
页面初始加载 js 脚本
function LoadList() {
$.ajax({
type: "POST",
url: "XXXX.aspx/LoadList",
dataType: "json",
contentType: "application/json;charset=utf-8",
timeout: 59000,
data: "{AccountCode:\"" + $("#txtAccountCode").val() + "\"}",
success: function (data) {
var json = $.parseJSON(data.d);
var strResult = unescape(json[0].strResult);
var strData = unescape(json[0].strData);
var strFirstCode = unescape(json[0].strFirstCode);
var strFirstName = unescape(json[0].strFirstName);
if (strResult == "OK") {
$("#ul_List").html(strData);
List_Click(strFirstCode, strFirstName);
}
else {
alert("列表刷新失败" + strResult);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
列表菜单点击的事件
function List_Click(Code,Name) {
$("#span_ListName").html(Name);
$("#txtListCode").val(Code);
LoadTable(1, 1);
}
cs后台代码:
[System.Web.Services.WebMethod]
public static String LoadCusPropList(string AccountCode)
{
string strData = "";
string strFirstCode = "";
string strFirstName = "";
int i = 1;
SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter("@AccountCode",AccountCode),
};
string strSQL = "select ParaGuid,ParaValue from Parameter "+
" where SoftID='Invoicing' and AccountCode=@AccountCode and ParaGroupCode='CusProp' " +
" and bStop=0 order by ParaOrder ";
using (SqlDataReader myDr = SqlHelper.ExecuteReader(ClsParameter.ConnectionString, CommandType.Text, strSQL, paras))
{
if (myDr != null)
{
while (myDr.Read())
{
if (i == 1)
{
strData += "<li id='li_" + myDr["ParaGuid"].ToString() + "' ><a href='javascript:void(0);' οnclick=\"List_Click('" + myDr["ParaGuid"].ToString() + "','" + myDr["ParaValue"].ToString() + "');\">" + myDr["ParaValue"].ToString() + "</a></li>";
strFirstCode = myDr["ParaGuid"].ToString();
strFirstName = myDr["ParaValue"].ToString();
}
else
strData += "<li class=\"divider\"></li><li id='li_" + myDr["ParaGuid"].ToString() + "' ><a href='javascript:void(0);' οnclick=\"List_Click('" + myDr["ParaGuid"].ToString() + "','" + myDr["ParaValue"].ToString() + "');\">" + myDr["ParaValue"].ToString() + "</a></li>";
i++;
}
}
}
strData = Microsoft.JScript.GlobalObject.escape(strData);
strFirstCode = Microsoft.JScript.GlobalObject.escape(strFirstCode);
return "[{\"strResult\":\"OK\"," +
"\"strData\":\"" + strData + "\"," +
"\"strFirstCode\":\"" + strFirstCode + "\"," +
"\"strFirstName\":\"" + strFirstName + "\"" +
"}]";
}