TextBox 内容由弹出窗口选择返回的实现

在项目中很多时候Textbox 需要有弹出窗口来选择返回.这里简单介绍实现方式.

1.新建弹出选择窗口页面:

前台:

 

ExpandedBlockStart.gif 代码
             < TABLE  width ="100%"  align ="center" >
                
< 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 >

 

后台:

 

ExpandedBlockStart.gif 代码
         private   void  btnSelect_Click( object  sender, System.EventArgs e)
        {
            
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;
  }

转载于:https://www.cnblogs.com/andycai/archive/2010/03/26/1696952.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值