日期:2014-05-18  浏览次数:20413 次

常识性问题
gridview   设置允许分页,允许排序.然后绑定到dataset,如下:

this.gvList.DataSource   =   log.getDS;
this.gvList.DataBind();

但是我在点分页和排序的时候,都报错,说要我写相应的排序和分页事件,我记得这些功能不用写事件代码的,是不是我的   vs2005是试用版的原因?

------解决方案--------------------
有可能 建议换掉吧 帮你顶一下
------解决方案--------------------
你用个真分页的储存过程试下呢
------解决方案--------------------
那你就写试试看啊
------解决方案--------------------
我用vs.net2005不用敲代码,就可以连接数据库,并且分页。一点问题都没有。
只不过查询,删除,修改都要写代码。
我用的SQLServer2005 EXPRESS,VS.NET2005
------解决方案--------------------
但是我在点分页和排序的时候,都报错,说要我写相应的排序和分页事件,我记得这些功能不用写事件代码的,是不是我的 vs2005是试用版的原因?

---------------------------------
1。
确定+肯定告诉你不是VS05的问题

2。
"所谓不用写事件代码 "
asp.net 2.0 是指使用数据源控件(如SqlDataSource )自动绑定数据的那种形式,
1.x 是托拽 DataSet 以及 xxxDataAdapter 自动绑定的

3.
按你这样写法,就是手动绑定,你需要实现相关的事件处理程序,如

<%@ Page language= "C# " %>

<script runat= "server ">

void CustomersGridView_DataBound(Object sender, EventArgs e)
{
if (!IsPostBack)
{
// Call a helper method to display the current page number
// when the page is first loaded.
DisplayCurrentPage();
}
}

void CustomersGridView_PageIndexChanged(Object sender, EventArgs e)
{
// Call a helper method to display the current page number
// when the user navigates to a different page.
DisplayCurrentPage();
}

void DisplayCurrentPage()
{
// Calculate the current page number.
int currentPage = CustomersGridView.PageIndex + 1;

// Display the current page number.
Message.Text = "Page " + currentPage.ToString() + " of " +
CustomersGridView.PageCount.ToString() + ". ";
}

</script>

<html>
<body>
<form runat= "server ">

<h3> GridView PageIndexChanged Example </h3>

<asp:label id= "Message "
forecolor= "Red "
runat= "server "/>

<br/>

<asp:gridview id= "CustomersGridView "
datasourceid= "CustomersSource "
autogeneratecolumns= "true "
emptydatatext= "No data available. "
allowpaging= "true "
ondatabound= "CustomersGridView_DataBound "
onpageindexchanged= "CustomersGridView_PageIndexChanged "
runat= "server ">

<pagersettings mode= "Numeric "
position= "Bottom "
pagebuttoncount= "10 "/>

<pagerstyle backcolor= "LightBlue "/>

</asp:gridview>

<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id= "CustomersSource "