Cómo hacer que la vista de cuadrícula sea el último botón de columna

I am trying to make gridview last column fields Button.

Trying but could not do this.

It is possible while adding column in gridview using sql data source. But to do this using this binding method.

Aquí está mi código

 private void BindUserRoles()
        gvUserRoles.DataSource = UserRoles.GetAllRoles();
public List<UserRoles> GetAllRoles()
            List<UserRoles> userRoles = new List<UserRoles>();

            using (IDataAccess dataAccess = Mspl.MobileTracking.DataAccess.DataAccess.GetDataAccess("TrackingConnectionString"))
                var dataReader = dataAccess.RetrieveData("GetAllRoles", null);

                while (dataReader.Read())
                    UserRoles roles = new UserRoles();
                    roles.RoleId = dataReader["RoleId"].ToString();
                    roles.RoleName = dataReader["RoleName"].ToString();


            return userRoles;
        catch (Exception ex)

            return null;


<asp:GridView ID="gvUserRoles" runat="server" EnableModelValidation="True" 

preguntado el 28 de mayo de 14 a las 11:05

Yes it is possible, please show UI code, are you adding columns from code behind or from UI itself? -

@Iti- adding from code behind, not from UI -

Or maybe this is also helpfull: stackoverflow.com/questions/16398555/… -

3 Respuestas

Sep AutoGeneratedColumn=false and add templatefields like shown below.

Change your grid code like this-

                <asp:BoundField DataField="RoleId" HeaderText="RoleId" ItemStyle-CssClass="HideColumn" HeaderStyle-HorizontalAlign="Left"/>
                <asp:TemplateField HeaderText="Role Name" HeaderStyle-CssClass="normalText">
                        <asp:Label ID="lblRoleName" CssClass="normalText" runat="server" Text='<%# Bind("RoleName") %>'></asp:Label>
                        <asp:Button ID="btnEditRole" runat="server" Text="Edit" OnClick="EditRoles_Click"></asp:Button>

contestado el 30 de mayo de 14 a las 12:05

Just replace your current "last" column with a ButtonField, Por ejemplo:

<asp:ButtonField ButtonType="button" CommandName="MoreDetail" 
         HeaderText="More Details" Text="More Details" />

contestado el 28 de mayo de 14 a las 12:05

I am not adding from UI. I am adding from code behind - Azhar Shahid

Instead of adding the button, just hide it by default and if needed, make it visible from your code-behind. - Yair Nevet

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.