//asp.net+javascript
//[*/***]index.aspx
<html>
function SearchSupply(supplyName)
{
var ret= window.showModalDialog('showsupply.aspx?pSupplyName='+supplyName,window,'scroll:no;status:no;center:yes;dialogHeight:280px;dialogWidth:480px;');
if(ret!=null)
{
var newret = ret.split(",")
document.all.txtSupplyName.value=newret[1];
}
}
function onhelpkeydown()
{
if (event.keyCode==118)
{
var vSupplyName=document.all.txtSupplyName.value;
event.srcElement.value="正在查询,请稍候......";
if (event.srcElement.id=="txtSupplyName")
{
SearchSupply(vSupplyName);
}
}
}
厂家名称<asp:textbox id="txtSupplyName" runat="server" Width="216px"></asp:textbox>
</html>
//[**/**]index.aspx.cs
private void Page_Load(object sender, System.EventArgs e)
{
txtSupplyName.Attributes["onkeydown"]="onhelpkeydown();";
}
//[***/*]showsupply.aspx
<html>
<head>
<script language="javascript">
function retvalue()
{
window.returnValue=document.all.ListBox1.value;
window.opener=null;
window.close();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:listbox id="ListBox1" runat="server" Height="216px" Width="456px"></asp:listbox>
<DIV οnclick="javascript:window.self.close()">【关闭窗口】</DIV>
</form>
</body>
</HTML>
//[****/]showsupply.aspx.cs
public class showsupply : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ListBox ListBox1;
private string cnnStr=System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
private void Page_Load(object sender, System.EventArgs e)
{
string name=Request.QueryString["pSupplyName"].ToString().Trim();
ListBox1.Attributes["ondblclick"]="retvalue();";
ListBox1.Items.Clear();
OleDbConnection cnn=null;
OleDbCommand cmd=null;
OleDbDataReader dataReader=null;
string sql=null;
sql="select supplyid,supplyname from supplys where supplyname like '%"+ name +"%'";
cnn=new OleDbConnection(cnnStr);
cnn.Open();
cmd=new OleDbCommand(sql,cnn);
dataReader=cmd.ExecuteReader();
while(dataReader.Read())
{
ListBox1.Items.Add(dataReader.GetString(0)+","+dataReader.GetString(1));
}
dataReader.Close();
cmd.Dispose();
cnn.Close();
if(ListBox1.Items.Count<=0)
{
ListBox1.Items.Add(",,,");
}
}
}