【问题标题】:Button click event in DataListDataList 中的按钮单击事件
【发布时间】:2012-10-14 06:14:10
【问题描述】:

我想通过DataList中的按钮点击事件来改变按钮的状态。请在这方面帮助我。

<asp:DataList ID="DataList1" CaptionAlign="Right" runat="server" Width="100%" Visible="true">
      <ItemTemplate>
            <table style="border-bottom:0px; border-left:0px; border-right:0px;" width="100%"  border="0" cellspacing="0" cellpadding="0">                                                                            
              <tr>
                  <td width="120px"><asp:Label ID="lbl_ccode" runat="server" Text='<%#Bind("Fld_Couponcode")%>' ></asp:Label></td>
                  <td width="140px"><asp:Label ID="lbl_cval" runat="server" Text='<%#Bind("Fld_CouponValue")%>' ></asp:Label></td>
                  <td width="140px"><asp:Label ID="bl_status" runat="server" Text='<%#Bind("fld_status")%>' ></asp:Label></td>
                  <td width="140px"><asp:Button ID="btnstatus" runat="server" Text='<%#Bind("fld_status")%>' /></td>
             </tr>                                                                                                 </table>
      </ItemTemplate>
      <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
      <HeaderStyle BackColor="#507CD1" Font-Bold="True" HorizontalAlign="Left" ForeColor="White" />
</asp:DataList>

【问题讨论】:

    标签: c# javascript asp.net vb.net


    【解决方案1】:

    处理DataGrid.ItemCommand Event

    在 DataGrid 控件中单击任何按钮时发生。

    <asp:Button ID="btnstatus" CommandName="ChangeStatus" 
    runat="server" Text='<%#Bind("fld_status")%>' />
    
      void ItemsGrid_Command(Object sender, DataGridCommandEventArgs e)
      {
    
         switch(((Button)e.CommandSource).CommandName)
         {
    
            case "ChangeStatus":
    
             // Add your code here
    
               break;
    
            default:
               // Do nothing.
               break;
    
         }
    
      }
    

    【讨论】:

    • CommandName ="ChangeStatus" 在单击按钮时不起作用。请帮忙。
    • Private Sub ItemsGrid_Command(ByVal sender As [Object], ByVal e As DataGridCommandEventArgs) Select Case DirectCast(e.CommandSource, Button).CommandName Case "Assigned" Dim status1 As Button = CType(e.Item .FindControl("btnstatus"), Button) status1.Text = "Redemed" Exit Select Case Else ' 什么也不做。退出选择结束选择结束子
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    相关资源
    最近更新 更多