O controle do datagrid é famoso demais, então eu usei muitas coisas antes. Isso é principalmente sobre o controle de dados do Datalist.
O controle de dados é realmente muito poderoso. Interseção Interseção
É realmente uma dor de cabeça.
No entanto, o Datalist não fornece uma função de paginação construída, mas não significa que não possamos usar o controle de dados para implementar a paginação.
Abaixo está todo o código original.
(Este programa é testado sob o .NET Framework Beta 2)
< % @ página de página = c# %>
< % @ Importar namespace = System.data %>
< % @ Importar namespace = System.data.oledb %>
<idioma script = c# runat = servidor>
/*
Criar pela faca voadora
http://www.aspcn.com
2001-7-25 01:44
Suporte .NET Framework Beta 2
*/
OLEDBCONNECTION MYCONN;
int PageSize, RecordCount, PageCount, CurrentPage;
public void Page_load (objeto SRC, EventArgs e)
{{
// Defina o PageSize
PageSize = 10;
// conectar
String myconnString = provedor = microsoft.jet.oledb.4.0;
myconn = new OLEDBConnection (MyConnString);
myconn.open ();
// O primeiro pedido de execução
if (! Page.ispostback)
{{
listBind ();
CurrentPage = 0;
ViewState [PageIndex] = 0;
// quantos registros são calculados no total
RecordCount = CalculatCord ();
lblRecordCount.Text = RecordCount.ToString ();
// quantas páginas são calculadas no total
pageCount = RecordCount/PageSize;
lblPageCount.Text = PageCount.ToString ();
ViewState [PageCount] = PageCount;
}
}
// Calcule quantos registros existem no total
Public int calculultCord ()
{{
int intcount;
string strCount = selecione count (*) como CO da pontuação;
OLEDBCOMAND MYCOMM = new OLEDBCommand (StrCount, Myconn);
OLEDBDATAREADER DR = myComm.ExecteReader ();
if (Dr.Read ()))
{{
intcount = int32.parse (dr [co] .toString ());
}
outro
{{
intcount = 0;
}
dra.close ();
Retornar intcount;
}
ICOLLECTION CREATESOURCE ()
{{
int startIndex;
// Defina o endereço inicial da importação
startIndex = currentPage*PageSize;
string strsel = selecione * da pontuação;
conjunto de dados ds = new DATASET ();
OLEDBDATADAPTER MYADAPTER = new OleDbdataadapter (Strsel, Myconn);
MyAdapter.fill (DS, StartIndex, PageSize, Score);
Return ds.Tables [score] .DefaultView;
}
public void listBind ()
{{
score.dataSource = createSource ();
score.databind ();
lbnnextpage.enabled = true;
lbnprevpage.enabled = true;
if (currentpage == (pageCount-)) lbnnextpage.enabled = false;
if (currentpage == 0) lbnprevpage.enabled = false;
lblCurrentPage.Text = (CurrentPage+1) .Tring ();
}
public void Page_OnClick (remetente de objeto, commandEventArgs e)
{{
CurrentPage = (int) ViewState [PageIndex];
pageCount = (int) ViewState [PageCount];
string cmd = e.comandname;
// juiz o CMD para determinar a direção da página girando
Switch (CMD)
{{
Caso seguinte:
if (currentpage <(pageCount-)) CurrentPage ++;
Quebrar;
Caso anterior:
if (currentpage> 0) currentpage-;
Quebrar;
}
ViewState [PageIndex] = CurrentPage;
listBind ();
}
</script>
<html>
<head>
<Title> </title>
</head>
<Body>
<Form runat = servidor>
Juntos <asp: rótulo id = lblrecordCount ICOLOR = RED RUNAT = servidor />
A corrente é <asp: rótulo id = lblcurrentpage intecolor = vermelho runat = server /> /<asp: rótulo id = lblPageCount INCOLOR = RED RAUNAT = servidor />
<ASP: Datalist ID = Score Runat = Servidor
Headstyle-backcolor =#aaaadd
alternatingItemstyle-backcolor = Gainsboro
EditItEmstyle-backcolor = amarelo
"
<TeMTemplate>
Nome: < %# databinder.eval (container.dataitem, nome) %>
<asp: linkbutton id = btnSelect text = editor commandName = edit runat = server />
</itemTemplate>
</asp: Datalist>
<asp: linkbutton id = lbnprevpage text = Page anterior commandName = prev oncommand = page_onClick runat = server />
<asp: linkbutton id = lbnnextpage text = seguinte commandName = a seguir oCommand = page_onClick runat = server />
</morm>
</body>
</html>
Os resultados em execução são como mostrados acima :)
Quando você escreve o programa, o mais importante é pensar sobre isso sozinho. A pergunta é muito simples, ninguém está disposto a responder ainda.
Pensar muito e verificar informações está realmente ganhando.