The DataGrid control is too famous, so I used a lot of things before. The repeater function is too little, and there is nothing to say. This is mainly about the DataList control.
The DataList control is actually very powerful. He supports selection and editing. The method of implementing is also very simple, but the most headache is that it has a built -in paging function like the DataGrid control. Such a good control cannot be paged! Intersection Intersection
It is indeed a headache.
However, DataList does not provide a built -in paging function, but it does not mean that we cannot use the DataList control to implement the paging. Since it does not give me a paging function, we have to do it ourselves.
Below is all the original code. The practical method is similar to the paging in PHP, but here is the combination of DataAdapter and DataSet, not the SQL statement in PHP directly.
(This program is tested under the .NET Framework Beta 2)
< % @ page language = c# %>
< % @ Import namespace = System.data %>
< % @ Import namespace = System.data.OLEDB %>
<script Language = C# Runat = Server>
/*
Create by flying knife
http://www.aspcn.com
2001-7-25 01:44
support .NET Framework Beta 2
*/
OLEDBCONNECTION MyConn;
int PageSize, RecordCount, PageCount, CurrenTPage;
public void page_load (Object SRC, EventArgs E)
{{
// Set pagesize
pagesize = 10;
// Connect
String myconnstring = Provider = microsoft.jet.OLEDB.4.0; data source =+server.mappath (.)+.. // db1.mdb;;
myconn = new oledbconnection (myconnstring);
myconn.open ();
// The first request for execution
if (! Page.ispostback)
{{
listBind ();
Currentpage = 0;
ViewState [pageIndex] = 0;
// How many records are calculated in total
RecordCount = CalculateCord ();
lblRecordCount.text = RecordCount.tostring ();
// How many pages are calculated in total
pagecount = RecordCount/PageSize;
lblpageCount.text = PageCount.tostring ();
ViewState [PageCount] = PageCount;
}
}
// Calculate how many records are there in total
Public int CalculteCord ()
{{
int intcount;
string strcount = select count (*) as co from score;
OLEDBCOMMAND Mycomm = New OLEDBCOMMAND (StrCount, Myconn);
OLEDBDataReader Dr = Mycomm.executereader ();
if (Dr.read ()))
{{
intCount = int32.parse (DR [Co] .tostring ());
}
else
{{
intcount = 0;
}
dra.close ();
Return intcount;
}
iCollection CreateSource ()
{{
int Startindex;
// Set the starting address of the import
startIndex = CurrenTPage*PageSize;
string strsel = Select * from score;
dataset 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 (Object SENDER, Commandeventargs E)
{{
Currentpage = (int) viewState [pageindex];
pagecount = (int) viewState [PageCount];
string cmd = e.Comandname;
// Judge CMD to determine the direction of the page turning
Switch (CMD)
{{
case next:
if (CurrentPage <(PageCount-)) CurrentPage ++;
Break;
Case Prev:
if (Currentpage> 0) CurrentPage-;
Break;
}
ViewState [pageIndex] = CurrentPage;
listBind ();
}
</script>
<html>
<head>
<Title> </title>
</head>
<body>
<FORM RUNAT = Server>
Together <asp: label ID = lblRecordcount Forecolor = Red Runat = Server />
The current is <asp: label ID = lblcurrentpage forecolor = red runat = server /> /<asp: label id = lblpageCount Forecolor = red raunat = server />
<ASP: DataList ID = Score Runat = Server
headstyle-backcolor =#AAAADD
alternatingItemstyle-backColor = Gainsboro
EdititeMSTYLE-BACKCOLOR = YELLOW
"
<Temtemplate>
Name: < %# DataBinder.eval (Container.Dataitem, name) %>
<asp: linkbutton id = btnselect text = editor CommandName = edit runat = server />
</itemTemplate>
</asp: datalist>
<asp: linkbutton id = lbnprevpage text = Previous page commandname = Prev OnCommand = Page_onClick Runat = Server />
<asp: linkbutton id = lbnnextpage text = Next commandname = Next OnCommand = Page_onClick Runat = Server />
</form>
</body>
</html>
The running results are as shown above :)
When you write the program, the most important thing is to think about it yourself. The question is too simple, no one is willing to answer yet.
Thinking a lot and checking information is really gaining.