Ir ao conteúdo
  • Cadastre-se

Datalist com paginação em uma aplicação aspx


Visitante: tchelocallo

Posts recomendados

Visitante: tchelocallo
 

Galera, boa tarde! Preciso da ajuda de vocês, estou fazendo um “Datalist” com paginação, porém quando dou um debug ele aparece à seguinte mensagem:

Error 1 'btnPrev_Click' não é membro de 'ASP.default_aspx'. E:\DatalisDorta\Default.aspx 16

Error 2 'btnNext_Click' não é membro de 'ASP.default_aspx'. E:\DatalisDorta\Default.aspx 18

Segue abaixo o código fonte para visualização.

html xmlns="http://www.w3.org/1999/xhtml" >

<head>

<title>Datalist Dorta</title>

</head>

<body>

<form id="form1" method="post" runat="server">

<div>

<table width="100%" border="0">

<tr>

<td>  <asp:label id="lblCurrentPage" runat="server"></asp:label></td>

</tr>

<tr>

<td>  <asp:Button id = "btnPrev" OnClick = "btnPrev_Click" Text = "<<" runat = "server" />

 <asp:Button id="btnNext" Onclick = "btnNext_Click" Text = ">>" runat = "server" /></td>

</tr>

</table>

<table border="1">

<asp:DataList ID="DataList1" runat="server">

<ItemTemplate>

<tr>

<td>  <b><%#DataBinder.Eval(Container.DataItem, "ItemName") %> </b></td>

<td>  <b><%#DataBinder.Eval(Container.DataItem, "ItemDescription") %> </b></td>

<td>  <b><%#DataBinder.Eval(Container.DataItem, "ItemPrice") %> </b></td>

<td>  <b><%#DataBinder.Eval(Container.DataItem, "ItemInStock") %> </b></td>

</tr>

</ItemTemplate>

</asp:DataList>

</table>

</div>

</form>

</body>

</html>

===============================================================================

using System;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

public int CurrentPage

{

get

{

// look for current page in ViewState

object o = this.ViewState["_CurrentPage"];

if (o == null)

return 0; // default to showing the first page

else

return (int)o;

}

set

{

this.ViewState["_CurrentPage"] = value;

}

}

private void Page_Load(object sender, System.EventArgs e)

{

// Call the ItemsGet method to populate control,

// passing in the sample data.

ItemsGet();

}

private void ItemsGet()

{

// Read sample item info from XML document into a DataSet

DataSet Items = new DataSet();

Items.ReadXml(MapPath("Items.xml"));

// Populate the repeater control with the Items DataSet

PagedDataSource objPds = new PagedDataSource();

objPds.DataSource = Items.Tables[0].DefaultView;

objPds.AllowPaging = true;

objPds.PageSize = 3;

objPds.CurrentPageIndex = CurrentPage;

lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of "

+ objPds.PageCount.ToString();

// Disable Prev or Next buttons if necessary

btnPrev_Click.Enabled = !objPds.IsFirstPage;

btnNext.Click.Enabled = !objPds.IsLastPage;

DataList1.DataSource = objPds;

DataList1.DataBind();

}

private void btnPrev_Click(object sender, System.EventArgs e)

{

// Set viewstate variable to the previous page

CurrentPage -= 1;

// Reload control

ItemsGet();

}

private void btnNext_Click(object sender, System.EventArgs e)

{

// Set viewstate variable to the next page

CurrentPage += 1;

// Reload control

ItemsGet();

}

}

Link para o comentário
Compartilhar em outros sites

O erro nem parece referir ao DataList em si....

Esta dizendo que sua página não possui os métodos 'btnPrev_Click' e 'btnNext_Click' definidos como eventos OnClick dos botões, o que é estranho porque pelo código que colocou existem os 2 métodos.

Tem algo errado nessa questão... tente retirar os eventos OnClick dos botões e rodar a aplicação.... e depois adiciona-los...

Pode ser que encontre o erro...

ATT,

Leonardo

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...