CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    429

    Question Possible to move [Edit] button on the RIGHT of a GridView row? (ASP.NET VS2008 C#)

    I have an .aspx webpage that contains a GridView (gvInfo), the GridView itself is edit'able (as shown below) by enabling "AutoGenerateEditButton=true", this allows for me to display the EDIT button on the left side of the GridView so that users can select it and then edit the contents of the row.

    But, by default the EDIT button is located on the LEFT of the rows, and with the design of my website it looks very odd, I would much prefer - if it is possible - to display the EDIT button on the RIGHT side of the rows - does anyone have a clue if this is possible and if so how it could be accomplished?

    Code:
    <asp:GridView ID="gvInfo" runat="server" Height="99px" CellSpacing="5" AutoGenerateColumns="False" CellPadding="2"
                    AllowPaging="False"
                    AutoGenerateEditButton="true" OnRowEditing="gvRegularDosage_RowEditing"
                    OnRowCancelingEdit="gvRegularDosage_RowCancelingEdit" OnRowUpdating="gvRegularDosage_RowUpdating"
                    EmptyDataText="No records found" >
                    <Columns>
                          ...
                          ...
                    </Columns>
                </asp:GridView>
    Any help would be greatly appreciated.
    Thanks,

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Possible to move [Edit] button on the RIGHT of a GridView row? (ASP.NET VS2008 C#

    Instead of AutoGenerateEditButton="true", add a column of type CommandField
    Code:
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowEditButton="True" />
                </Columns>
            </asp:GridView>

  3. #3
    Join Date
    Jul 2008
    Posts
    21

    Re: Possible to move [Edit] button on the RIGHT of a GridView row? (ASP.NET VS2008 C#

    Hi, You can also do in the following way by using a linkbutton/button as an item in the template field and then use the row command method to perform the editing role or whatever is required. You can just use a template field in the following way:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" onRowCommand="RowCommand">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <table>
    <tr>
    <td>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </td>
    <td>
    <asp:LinkButton ID="LinkButton1" runat="server" Text="Edit"></asp:LinkButton>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:CommandField ShowEditButton="True" />
    </Columns>
    </asp:GridView>

    and you can use the rowcommand method for describing the functionality.
    I hope this would solve your problem.

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

Featured