zoukankan      html  css  js  c++  java
  • 关于Repeater中绑定的控件不触发ItemCommand事件

    今天遇到 在repeater 中使用一个button,点击button然后跳转另外一个页面。

    html.

     1 <asp:Repeater ID="repeater" runat="server" OnItemCommand="repeater_ItemCommand">
     2             <ItemTemplate>
     3                 <table>
     4                     <tr>
     5                         <td>id:<%# Eval("id") %></td>
     6                         <td>
     7                             <%--<asp:ImageButton id="bnt12"  ImageUrl="~/help.png" runat="server" CommandName="跳转"/>--%>
     8                             <asp:Button runat="server"  Text="跳转" ID="bnt1"  CommandName="跳转" />
     9                         </td>
    10                     </tr>
    11                 </table>
    12             </ItemTemplate>
    13         </asp:Repeater>

    cs.

    1      protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    2         {
    3             if (e.CommandName == "跳转")
    4             {
    5                 Response.Redirect("http://www.baidu.com");
    6             }
    7         }

    当点击button的时候,发现是不会跳转的,

    在网上也一直找了很多资料,最后发现可能的原因是

      1.当点击button的时候 是刷新页面 repeater 重新绑定了一遍, 把itemcommand 刷新没了,

      2.使用dopostback 类型的都可以跳页面,既linkbutton.

      解决方法:点击button的时候 不让repeater重新绑定数据 or 使用dopostback。

  • 相关阅读:
    小猫爬山
    方格取数
    Bash 脚本编程
    树链剖分学习笔记
    输入输出优化
    没有上司的舞会
    线性dp 之 麻烦的聚餐
    飞翔
    挖地雷
    The Prices
  • 原文地址:https://www.cnblogs.com/chongde/p/4169821.html
Copyright © 2011-2022 走看看