DataGrid分页问题-上一页 下一页是空连接 为何???
代码如下:
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("new.mdb");
OleDbConnection objConnection=new OleDbConnection(strConnection);
objConnection.Open();
OleDbCommand objCommand1 = new OleDbCommand("select * from admin ",objConnection);
dgrdMain.DataSource=objCommand1.ExecuteReader();//dgrdMain就是下面的DATAGRID的ID
dgrdMain.DataBind();
}
private void dgrdMain_PageIndexChanged(object source,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgrdMain.CurrentPageIndex=(int)e.NewPageIndex;
dgrdMain.DataBind();
}
</script>
DataGrid属性设置如下:
<asp:DataGrid id="dgrdMain"
cellpadding="2" Width="350"
showheader="true" borderwidth="1"
runat="server" DataKeyField="adminid"
AutoGenerateColumns="false"
ItemStyle-HorizontalAlign="center"
BorderColor="#006699"
AllowPaging="true"
AllowCustomPaging="true"
PagerStyle-HorizontalAlign="Left"
PageSize="5"
PagerStyle-PrevPageText="上一页"
PagerStyle-NextPageText="下一页"
OnPageIndexChanged="dgrdMain_PageIndexChanged"
>
<columns>
<asp:BoundColumn HeaderText="编号" DataField="adminid" HeaderStyle-HorizontalAlign="center" HeaderStyle-BorderStyle="dashed" ItemStyle-BorderStyle="dashed"/>
<asp:BoundColumn HeaderText="用户名" DataField="username" HeaderStyle-HorizontalAlign="center" HeaderStyle-BorderStyle="dashed" ItemStyle-BorderStyle="dashed"/>
<asp:BoundColumn HeaderText="密码" DataField="password" HeaderStyle-HorizontalAlign="center" HeaderStyle-BorderStyle="dashed" ItemStyle-BorderStyle="dashed"/>
</columns>
</asp:DataGrid>
问题是:上一页和下一页上根本就没有连接是空连接,这是为什么啊???
请 路过的朋友帮帮忙啊!我看了其他帖子也都是这样写的,可为什么会没有连接呢?