【问题标题】:Grindview with imagebutton and rowcommandGrindview 与 imagebutton 和 rowcommand
【发布时间】:2011-04-25 02:51:56
【问题描述】:

我知道这是一个常见问题,但我找不到解决方案。我希望你能帮助我。 我尝试将图像按钮控件绑定到网格视图中。 我想处理单击按钮所在行的数据

我的 aspx 文件看起来像

   <asp:ImageButton ID="Button1"
                                  runat="server"
                                  ImageUrl="~/Images/deny.png"
                                  Height="45" Width="45" 
                                  CommandName="SelectComment"
                                  CommandArgument='<%# Container.DataItemIndex %>' />

vb 文件看起来像

Protected Sub KontaktAnfragen_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles KontaktAnfragen.RowCommand

    Dim rowIndex As Integer
    Dim commentHiddenField As HiddenField

    If e.CommandName = "SelectComment" Then
        rowIndex = Integer.Parse(e.CommandName.ToString)

问题在于页面不处理点击。它什么都不做。它甚至不跳转到 RowCommand 函数中

最好的问候

【问题讨论】:

    标签: asp.net vb.net gridview imagebutton rowcommand


    【解决方案1】:

    如果我正确理解您的代码,您需要将OnClick="KontaktAnfragen_RowCommand" 添加到 ImageButton。

    【讨论】:

      【解决方案2】:

      您需要将“KontaktAnfragen_RowCommand”分配给图像按钮所在的 Gridview 的 OnRowCommand 事件。

      OnRowCommand="KontaktAnfragen_RowCommand"
      

      我刚刚注意到,在您的上述代码中,您是否应该使用 CommandArgument 值而不是 CommandName 值来代替 rowIndex

      我也不确定你是否需要使用ToString,但如果你这样做,请使用ToString() 而不是ToString,因为它是一个方法调用。

      类似这样的东西(包括 if 语句的格式等)?:

      if (e.CommandName == "SelectComment") Then
              rowIndex = Integer.Parse(e.CommandArgument)
      

      【讨论】:

        猜你喜欢
        • 2012-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-26
        • 1970-01-01
        相关资源
        最近更新 更多