在项目中很多时候Textbox 需要有弹出窗口来选择返回.这里简单介绍实现方式.
1.新建弹出选择窗口页面:
前台:
< tr >
< td class ="td" align ="center" >
< asp:TextBox id ="txtSearchLike" runat ="server" Width ="254px" ></ asp:TextBox >< asp:button id ="btnSelect" runat ="server" Width ="70px" CssClass ="button" Text ="Select" ></ asp:button ></ td >
</ tr >
< tr >
< td class ="td" align ="center" colSpan ="2" >< asp:listbox id ="lbxResult" runat ="server" Width ="325px" Height ="136px" SelectionMode ="Multiple" ></ asp:listbox ></ td >
</ tr >
< tr >
< td class ="td" align ="center" >
< asp:button id ="btnConfirm" runat ="server" Width ="70px" CssClass ="button" Text ="Confirm" ></ asp:button ></ td >
</ tr >
</ TABLE >
后台:
{
try
{
string SearchLike = this .txtSearchLike.Text.Trim();
string col = Request.QueryString[ " SearchLike " ]; // 参数传入
string org = Request.QueryString[ " org " ];
BindListBox(SearchLike,col,org);
}
catch (Exception ex)
{
}
}
public void BindListBox( string SearchLike, string col, string org)
{
try
{
ListBox 内容绑定
}
catch (Exception ex)
{
}
}
private void btnConfirm_Click( object sender, System.EventArgs e)
{
try
{
string strScript = "" ;
string rtnValue = "" ;
for ( int i = 0 ;i < this .lbxResult.Items.Count;i ++ )
{
if ( this .lbxResult.Items[i].Selected)
{
string valueSelected = this .lbxResult.Items[i].Value;
if (valueSelected != "" )
{
rtnValue += this .lbxResult.Items[i].Value + " , " ;
}
}
}
if (rtnValue == "" )
{
rtnValue = " , " ;
}
strScript = " <script language = javascript> " +
" dialogArguments[0].value = ' " + rtnValue.Remove(rtnValue.Length - 1 , 1 ).Trim() + " '; " +
" window.close(); " +
" </script> " ; // 返回值
RegisterClientScriptBlock( " e " ,strScript);
return ;
}
catch (Exception ex)
{
}
}
页面使用:
前台: Textbox
<asp:textbox id="txtOrg" Runat="server" ReadOnly="True"></asp:textbox><input id="btnOrg" οnclick="return GetOrgInfo();" type="button" value="V" name="btnOrg" runat="server">
JS:
function GetOrgInfo()
{
var colname = "org";
var url = "SearchForSupply.aspx?SearchLike="+colname+"&"+new Date().getTime()+"&org=";
window.showModalDialog(url,[document.getElementById("txtOrg")],'dialogWidth:400px;dialogHeight:300px;status:no;help:no;scroll:no;menubar:no;resizable:yes');
return true;
}