Cómo hacer que la vista de cuadrícula sea el último botón de columna
Frecuentes
Visto 1,097 equipos
0
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();
gvUserRoles.DataBind();
}
public List<UserRoles> GetAllRoles()
{
try
{
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();
userRoles.Add(roles);
}
}
return userRoles;
}
catch (Exception ex)
{
return null;
}
}
<asp:GridView ID="gvUserRoles" runat="server" EnableModelValidation="True"
</asp:GridView>
3 Respuestas
1
Sep AutoGeneratedColumn=false
and add templatefields like shown below.
Change your grid code like this-
<Columns>
<asp:BoundField DataField="RoleId" HeaderText="RoleId" ItemStyle-CssClass="HideColumn" HeaderStyle-HorizontalAlign="Left"/>
<asp:TemplateField HeaderText="Role Name" HeaderStyle-CssClass="normalText">
<ItemTemplate>
<asp:Label ID="lblRoleName" CssClass="normalText" runat="server" Text='<%# Bind("RoleName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnEditRole" runat="server" Text="Edit" OnClick="EditRoles_Click"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
contestado el 30 de mayo de 14 a las 12:05
0
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
0
Please try below link
agregueboundField a gridview en el archivo de código subyacente C#
Code project link
http://www.codeproject.com/Articles/13461/how-to-create-columns-dynamically-in-a-grid-view
contestado el 23 de mayo de 17 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# asp.net gridview or haz tu propia pregunta.
Yes it is possible, please show UI code, are you adding columns from code behind or from UI itself? - Incredible
@Iti- adding from code behind, not from UI - Azhar Shahid
stackoverflow.com/questions/2418379/… And there is one more link : stackoverflow.com/questions/10397856/… - Incredible
Or maybe this is also helpfull: stackoverflow.com/questions/16398555/… - DatRid
Please try below link stackoverflow.com/questions/11971035/… y codeproject.com/Artículos/13461/… - Deepak Joshi