无论我改变什么,我都无法在页面中看到我的gridview。我已经使用过Datasource和Databind,Visible是True,我想至少我应该只看到表而不是什么。另外,我很抱歉,我没有翻译这个,有些东西是西班牙语但我认为你会理解上下文,尽管名字是西班牙语。如果这是一个问题,我可以编辑和翻译。 感谢。
aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Masterpage.Master" CodeBehind="ListarRemateCerrado.aspx.cs"
Inherits="Interfaz.ListarRemateCerrado" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<p>CIERRE DE REMATE</p>
<asp:ListBox ID="lstRemates" runat="server"></asp:ListBox>
<asp:GridView ID="grvRemates" runat="server" AutoGenerateColumns="False" AllowSorting="True" OnPageIndexChanging="grvRemates_PageIndexChanging"
OnSorting="grvRemates_Sorting" AllowPaging="True" PageSize="5" AutoGenerateSelectButton="True"
ShowHeaderWhenEmpty="True" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="ID Remate" SortExpression="Remate">
<ItemTemplate>
<asp:Label ID="lblRemate" runat="server" Text='<%# Eval("Remate") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comision Rematador" SortExpression="Comision">
<ItemTemplate>
<asp:Label ID="lblComision" runat="server" Text='<%#Eval("Comision")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView><br />
<asp:GridView ID="grvRemateSeleccionado" runat="server" AllowSorting="True" PageSize="5" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:Button ID="btnRefrescar" runat="server" Text="Refrescar" OnClick="btnRefrescar_Click" />
<asp:Button ID="btnVolver" runat="server" Text="Volver" OnClick="btnVolver_Click" CausesValidation="false" /> <br />
<asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>
<asp:Label ID="lblCorrecto" runat="server"></asp:Label>
</asp:Content>
aspx.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dominio;
namespace Interfaz
{
public partial class ListarRemateCerrado : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lstRemates.DataSource = Agencia.Instancia().devolverRemates();
lstRemates.DataTextField = "Datos";
lstRemates.DataValueField = "numero";
lstRemates.DataBind();
if (!IsPostBack)
{
List<Remate> ordenada = Agencia.Instancia().devolverRemates();
ordenada.Sort(new Remate.OrdenarXRemate());
Session["sortedView"] = ordenada;
BindData(ordenada);
Session["filtro"] = "numero";
Session["direccion"] = SortDirection.Ascending;
}
}
protected void btnRefrescar_Click(object sender, EventArgs e)
{
List<Remate> ordenada = Agencia.Instancia().devolverRemates();
ordenada.Sort(new Remate.OrdenarXRemate());
Session["sortedView"] = ordenada;
BindData(ordenada);
Session["filtro"] = "numero";
Session["direccion"] = SortDirection.Ascending;
}
protected void btnVolver_Click(object sender, EventArgs e)
{
Response.Redirect("MenuPrincipalAdmin.aspx");
}
protected void BindData(List<Remate> r)
{
lstRemates.DataSource = r;
lstRemates.DataBind();
}
protected void grvRemates_Sorting(object sender, GridViewSortEventArgs e)
{
List<Remate> ordenada = (List<Remate>)Session["sortedView"];
if (e.SortExpression == "Remate") ordenada.Sort(new Remate.OrdenarXRemate());
if (e.SortExpression == "Comision") ordenada.Sort(new Remate.OrdenarXComision());
if (e.SortExpression == Session["filtro"].ToString().Trim())
{
SortDirection aux = (SortDirection)Session["direccion"];
if (SortDirection.Ascending == aux)
{
Session["direccion"] = SortDirection.Descending;
ordenada.Reverse();
}
else
{
Session["direccion"] = SortDirection.Ascending;
}
}
Session["filtro"] = e.SortExpression;
Session["sortedView"] = ordenada;
BindData(ordenada);
}
protected void grvRemates_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grvRemates.PageIndex = e.NewPageIndex;
BindData((List<Remate>)Session["sortedView"]);
}
protected void grvRemates_SelectedIndexChanged(object sender, EventArgs e)
{
CargarPaquete();
}
private void CargarPaquete()
{
GridViewRow row = grvRemates.SelectedRow;
Label lbl = row.FindControl("lblRemate") as Label;
int codigo = int.Parse(lbl.Text);
grvRemateSeleccionado.DataSource = Agencia.Instancia().devolverLotesRemate(codigo);
grvRemateSeleccionado.DataBind();
}
}
}
答案 0 :(得分:1)
您无法为网格设置数据绑定方法,
grvRemates.DataSource= Agencia.Instancia().devolverRemates();
grvRemates.DataBind();