Results 1 to 4 of 4

Thread: [RESOLVED] [2005] CommandArgument Gridview Itemtemplate

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved [RESOLVED] [2005] CommandArgument Gridview Itemtemplate

    Hey,
    I know I've seen this around before but I forgot how to do it... I have a couple buttons within a Gridview's Itemtemplate. I need to assign the commandargument to the buttons and not sure exactly how to do it...

    I've been messing around in the RowCreated event and just in the markup

    Code:
                            <asp:Button ID="btnDetails" runat="server" CommandName="Details" CommandArgument='<%# notsurewhattoputhere %>' Text="Details" Width="80px" /><br />
    Code:
        Protected Sub gvItemGrid_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvItemGrid.RowCreated
            If e.Row.RowIndex > 0 Then
                Dim btnDetails As Button = DirectCast(e.Row.Cells(5).FindControl("btnDetails"), Button)
                
                btnDetails.CommandArgument = e.Row.RowIndex.ToString
    
            End If
        End Sub

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] CommandArgument Gridview Itemtemplate

    You want the RowDataBound event.

    Do the FindControl (e.Row.FindControl()), cast it to a button, then assign the CommandArgument and CommandName properties.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [2005] CommandArgument Gridview Itemtemplate

    Cool thanks... Can it be done in the Markup also? or should I just stick with the databound event?

  4. #4
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: [2005] CommandArgument Gridview Itemtemplate

    You can do it in markup as well. I would suggest setting the CommandName in markup (if it's not a different name for different rows) but the command argument you should do in the event mentioned before by mendhak. In the markup it would be something like
    Code:
    <asp:Button ID="editButton" runat="server" CommandName="EditContainer" Text="Edit"
                                        CommandArgument="<%# CType(Container, GridViewRow).RowIndex %>" />
    But as you can see the code to set the command argument is .Net code and is not suggested to be put in markup.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width