1

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

我的 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 函数

此致

4

2 回答 2

2

You need to assign the "KontaktAnfragen_RowCommand" to the Gridview's OnRowCommand event the image button is in.

OnRowCommand="KontaktAnfragen_RowCommand"

I just noticed, in your aboove code, should you not be using the CommandArgument value instead of the CommandName value for the rowIndex?

Also I'm not sure you need to use ToString but if you do, use ToString() instead of ToString as it is a method call.

Something like this (included formatting of if statement, etc..)?:

if (e.CommandName == "SelectComment") Then
        rowIndex = Integer.Parse(e.CommandArgument)
于 2010-10-14T08:35:11.193 回答
2

If I understand your code correctly, you need to add OnClick="KontaktAnfragen_RowCommand" to the ImageButton.

于 2010-10-13T22:32:32.040 回答