Datagridコントロールはあまりにも有名ですので、以前は多くのものを使用しました。これは主にデータリストのコントロールに関するものです。
DataListコントロールは、実際には非常に強力です。交差点交差点
それは確かに頭痛です。
ただし、DataListは組み込まれたページング機能を提供しませんが、ページング機能を実装していないため、Datalist Controlを使用できないという意味ではありません。
以下は、すべての元のコードですが、PHPのページングに似ていますが、PHPのSQLステートメントではなく、データアダプターとデータセットの組み合わせです。
(このプログラムは.NETフレームワークベータ2でテストされています)
<% @ページ言語= C#%>
<% @ Import NameSpace = System.Data%>
<% @ namespace = system.data.oledb%>をインポートします
<スクリプト言語= c#runat = server>
/*
飛ぶナイフで作成します
http://www.aspcn.com
2001-7-25 01:44
サポート.NETフレームワークベータ2
*/
OLEDBCONNECTION MYCONN;
int Pagesize、RecordCount、PageCount、currentPage;
public void page_load(オブジェクトSRC、eventargs e)
{{
//ページサイズを設定します
Pagesize = 10;
// 接続する
string myconnstring = provider = microsoft.jet.oledb.4.0;
myConn = new oLedBConnection(myConnString);
myconn.open();
//実行の最初のリクエスト
if(!page.ispostback)
{{
listbind();
currentPage = 0;
viewstate [pageindex] = 0;
//合計で計算されるレコードの数
RecordCount = calculateCord();
lblRecordCount.Text = RecordCount.ToString();
//合計で計算されるページ数
pagecount = recordcount/pagesize;
lblpagecount.text = pagecount.toString();
viewstate [pagecount] = pagecount;
}
}
//合計でいくつのレコードがあるかを計算します
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());
}
それ以外
{{
intcount = 0;
}
dra.close();
intcountを返します。
}
icollection createSource()
{{
int startindex;
//インポートの開始アドレスを設定します
startindex = currentPage*Pagesize;
string strsel = select * from score;
データセットds = new DataSet();
oledbdatadapter myadapter = new oledbdataadapter(strsel、myconn);
myadapter.fill(ds、startindex、pagesize、score);
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(オブジェクト送信者、commandEventargs e)
{{
currentPage =(int)viewstate [pageindex];
pagecount =(int)viewstate [pagecount];
文字列cmd = e.comandname;
// CMDを裁判官ページの方向を決定する
スイッチ(CMD)
{{
次のケース:
if(currentPage <(pagecount-))currentPage ++;
壊す;
ケース前:
if(currentPage> 0)currentPage-;
壊す;
}
viewstate [pageindex] = currentPage;
listbind();
}
</script>
<html>
<head>
<title> </title>
</head>
<body>
<form runat = server>
一緒に<ASP:ラベルID = LBLRECORDCOUNT FORECOLOR = RED RUNAT = SERVER />
電流は<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>
名前:<%#databinder.eval(container.dataitem、name)%>
<asp:linkbutton id = btnselect text = editor commandname = edit runat = server />
</itemtemplate>
</asp:datalist>
<asp:linkbutton id = lbnprevpageテキスト=前のページコマンド名= prev oncommand = page_onclick runat = server />
<asp:linkbutton id = lbnnextpage text = next commandname = next oncommand = page_onclick runat = server />
</form>
</body>
</html>
実行中の結果は上記のとおりです:)
プログラムを書くとき、最も重要なことは自分でそれについて考えることです。質問はあまりにも単純で、誰もまだ答えないことはありません。
多くのことを考えて、情報をチェックすることは本当に増えています。