Repeater事件OnItemCommand取得行内控件

记录一下,主要是这句:
TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;

Repeater真是太强了,太灵活。除了Repeater别的都不用。

ExpandedBlockStart.gif 代码
< table >
    
< asp:Repeater  ID ="rptList"  runat ="server"  OnItemCommand ="rptList_ItemCommand" >
    
< ItemTemplate >
< tr >
    
< td >< asp:TextBox  ID ="txtNum"  runat ="server"  Text ='<%#Eval("ProNum")  % > '> </ asp:TextBox ></ td >
    
< td >< asp:Button  ID ="btnUpdate"  runat ="server"  Text ="更新"  CommandName ="update"  CommandArgument ='<%#Eval("PID")  % > ' /> </ td >
</ tr >
    
</ ItemTemplate >
    
</ asp:Repeater >
</ table >

 

 

ExpandedBlockStart.gif 代码
protected   void  rptList_ItemCommand( object  source, RepeaterCommandEventArgs e)
{
    
switch  (e.CommandName)
    {
        
case   " update " :
            
string  arg  =  e.CommandArgument.ToString(); // 取得参数
            
// 找到激发事件的行内控件,这个很有用,能将更多需要的参数值传递过来。
            TextBox txtNum  =  e.Item.FindControl( " txtNum " as  TextBox;
            
            
// 下面执行业务逻辑
             string  jsStr  =   " <script>alert('删除成功! "   +  txtNum.Text  +   " ')</script> " ;
            Page.ClientScript.RegisterClientScriptBlock(
this .GetType(),  " alert " , jsStr,  false );
            
break ;
    }
    Bind();
}
// 参考MSDN:
// http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.repeater.itemcommand.aspx

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值