我有这个网格视图:
<asp:GridView ID="GridViewCosts" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" ShowFooter="True" ShowHeaderWhenEmpty="True" AutoGenerateColumns="False" OnRowDeleting="GridViewCosts_RowDeleting" Width="387px" OnSelectedIndexChanged="GridViewCosts_SelectedIndexChanged" AllowPaging="true" AllowSorting="true"
PageSize="5" >
但这给了我错误:The data source does not support server-side data paging.
在后面的代码中我有这样的东西:
GridViewCosts.DataSource = rdr;
Line 55: GridViewCosts.DataBind();
如何分页我没有数据源的gridView
更新 我修改我有这个
<asp:GridView ID="GridViewCosts" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" ShowFooter="True" ShowHeaderWhenEmpty="True"
AutoGenerateColumns="False" OnRowDeleting="GridViewCosts_RowDeleting" Width="387px"
OnSelectedIndexChanged="GridViewCosts_SelectedIndexChanged"
OnPageIndexChanging="GridViewCosts_PageIndexChanging"
PageSize="5" >
在代码后面有这个:
public void getViewProfit()
{
string connectionString = cs.getConnection();
string query = "select Id ,name,value,Description,DateCreate from AllCostView where IdUser = '" + cui.getCurrentId() + "'";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand command = new SqlCommand(query, myConnection);
using (SqlDataReader rdr = command.ExecuteReader())
{
GridViewCosts.DataSource = rdr;
GridViewCosts.DataBind();
}
}
}
protected void GridViewCosts_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewCosts.PageIndex = e.NewPageIndex;
getViewProfit();
}
没有错误了,但仍然不显示分页