Hola, estoy tratando de mostrar un gridview, pero no consigo que se me muestre por pantalla.
Por un lado tengo IncidenceList.aspx
Código ASP:
Ver original<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="IncidenceList.aspx.cs" Inherits="Incidences.WEB.Admin.IncidenceList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<link href="<%: ResolveUrl("~/Content/DataTables/css/jquery.dataTables.css") %>" rel="stylesheet" />
<script src="<%: ResolveUrl("~/Scripts/DataTables/jquery.dataTables.js") %>"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#MainContent_GridView1').DataTable(
{
"oLanguage": { "sUrl": "//cdn.datatables.net/plug-ins/1.10.7/i18n/Spanish.json" },
"columnDefs": [
{
"render": function (data, type, row) {
return "<a href='EditIncidence?incidenceId=" + data + "'>" + data + "</a>";
},
"targets":0
},
{ "title": "Equipo", "targets": 1 },
{ "title": "Tipo de incidencia", "targets": 2 },
{ "title": "Mensage", "targets": 3 },
{ "title": "listado", "targets": 4 },
]
});
});
</script>
<div style =" margin-top:10px;margin-bottom:10px">
<asp:Button CssClass="btn btn-default" ID="cmdNew" runat="server" Text="Nueva incidencia" OnClick="cmdNew_Click" />
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id"></asp:BoundField>
<asp:BoundField DataField="Equipment" HeaderText="Equipment" SortExpression="Equipment"></asp:BoundField>
<asp:BoundField DataField="IncidenceType" HeaderText="IncidenceType" SortExpression="IncidenceType"></asp:BoundField>
<asp:BoundField DataField="Message" HeaderText="Message" SortExpression="Message"></asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource runat="server" ID="ObjectDataSource1" SelectMethod="GetData" TypeName="Incidences.WEB.Admin.IncidenceList"></asp:ObjectDataSource>
</asp:Content>
Por otro lado el aspx.cs
Código ASP:
Ver originalusing Incidences.Application;
using Incidences.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity;
using Incidences.WEB.Models;
namespace Incidences.WEB.Admin
{
public partial class IncidenceList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.UseAccessibleHeader = true;
if (GridView1.HeaderRow != null)
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
/// <summary>
/// Metodo que retorna los datos de lasincidencias para el listado de usuario
/// </summary>
/// <returns>Lista de incidencia del usuario</returns>
public List<IncidenceListAdmin>GetData()
{
ApplicationDbContext context = new ApplicationDbContext();
IncidenceManager incidenceManager = new IncidenceManager(context);
MessageManager messageManager = new MessageManager(context);
var incidences = incidenceManager.GetByUserId(User.Identity.GetUserId()).ToList()
.Select(i => new IncidenceListAdmin()
{
Id = i.Id,
Equipment = i.Equipment,
Status = i.Status.ToString(),
IncidenceType = i.IncidenceType.ToString(),
Message = messageManager.GetFirstMessage(i.Id).Text
});
return incidences.ToList();
}
protected void cmdNew_Click(object sender, EventArgs e)
{
Response.Redirect("CreateIncidence");
}
}
}
Este seria en el rol administrador, el caso es que tengo el mismo código en el rol administrador y ahi si que me muestra sin problemas.
Muchas gracias.