Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to write some code in your RowDataBound event for the given GridView you're binding to. In that method, you can add as many controls as you'd like dynamically with some simple code. In addition, you can leverage the CommandName and CommandArgument properties for easy click handling.</p> <p>Your RowDataBound event will have the following code in it.</p> <pre><code>If e.Row.RowType = DataControlRowType.DataRow Then Dim SpecialLink As New LinkButton() SpecialLink.CommandName = "FancyCommand" SpecialLink.CommandArgument = e.Row.RowIndex.ToString ''//Or your Unique Data Id too. SpecialLink.Text = "Click me to do custom work." e.Row.Cells(0).Controls.Add(SpecialLink) ''//Put it in whatever grid cell you'd like End If </code></pre> <p>Then you can use the RowCommand event to process your command easily enough.</p> <pre><code>Private Sub ProcessGridCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _ Handles gvComments.RowCommand Select Case e.CommandName Case "FancyCommand" DoSpecialProcessing(e.CommandArgument) End Select End Sub </code></pre> <p>I like to use the Select only because it makes it easy to add more custom commands later. You can easily redo this code for C# if needs be.</p> <p>In addition, if you need to add more than 1 link button, you can do it really fast in the code without having a bunch of placeholder links that may be set to visible or hidden.</p> <p>EDIT: So after a quick dig, if you want to call your JavaScript code, then ditch the CommandName/Command Arguments above and you can do the following:</p> <pre><code>SpecialLink.Attributes("OnClick") = "lnkDocumentOne_Click();" </code></pre> <p>You may need to create a "catch all" type JavaScript method to handle the various links that would be calling it, or you can also use the Page.RegisterClientScript method to register all the JavaScript methods and create those dynamically as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload