0

グリッドビューのすべてのセルにリンクボタンを動的に追加しています。ボタンの追加は機能しますが、偶数ハンドラーの起動は機能しません。関数を呼び出して処理するデータを渡すには、リンクボタンが必要です。私のコードは以下の通りです。私はこれまで私を手に入れているサイトから解決策を見つけました。現時点では、gridviewは青色のボタンでセルをロードします。それらをクリックすると、プレーンテキストに戻り、関数は呼び出されません。

Private Sub gv_datasource_options_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_datasource_options.RowDataBound
    Try
        If e.Row.RowType = DataControlRowType.DataRow Then
            For Each c As TableCell In e.Row.Cells
                If Len(c.Text) > 0 And c.Text <> "&nbsp;" Then
                    Dim v_lb As New LinkButton()
                    v_lb.Text = c.Text                        
                    AddHandler v_lb.Click, AddressOf add_datasource
                    v_lb.Attributes.Add("AutoPostback", "True")
                    v_lb.Attributes.Add("runat", "Server")
                    v_lb.Attributes.Add("AutoEventWireup", "True")
                    v_lb.CommandName = "NumClick"
                    v_lb.CommandArgument = e.Row.Cells(0).ToString & "|" & gv_datasource_options.HeaderRow.Cells(e.Row.Cells.GetCellIndex(c)).Text
                    c.Controls.Add(v_lb)
                    Dim sm As ScriptManager = ScriptManager.GetCurrent(Me)
                    sm.RegisterAsyncPostBackControl(v_lb)
                End If
            Next
        End If
    Catch ex As Exception
        cl_Error.cl_Erorr.LogError(ex, txt_userid.Value, ex.ToString)
    End Try
End Sub
Private Sub add_datasource(sender As Object, e As CommandEventArgs)
    Try
        hf_datasource_id.Value = Left(e.CommandArgument.ToString(), (Len(e.CommandArgument.ToString) - InStr(e.CommandArgument.ToString, "|")))
        hf_datasource_column.Value = Left(e.CommandArgument.ToString(), (Len(e.CommandArgument.ToString) - InStr(e.CommandArgument.ToString, "|")))
        hf_datasource_tableid.Value = tv_content.SelectedValue
        p_datasource.Visible = False
    Catch ex As Exception
        cl_Error.cl_Erorr.LogError(ex, txt_userid.Value, ex.ToString)
    End Try

End Sub
4

1 に答える 1

0

リンクボタンにイベント( "add_datasource")を追加するのではなく、GridViewのRowCommandイベントを使用してみてください。Gridviewの行コマンドイベントのリンクボタンでバブルされたイベントを(コマンド名とコマンド引数とともに)確実にフェッチできるようになります。

于 2012-05-09T13:49:05.630 に答える