0
我有這個網格視圖:如何分頁的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" AllowPaging="true" AllowSorting="true"
PageSize="5" >
但是這給在我的錯誤:The data source does not support server-side data paging.
在後面的代碼我有這樣的事情:
GridViewCosts.DataSource = rdr;
Line 55: GridViewCosts.DataBind();
如何尋呼我的gridView沒有數據源
UPDATE 我修改我有這個
<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();
}
有沒有錯誤更多,但仍然沒有顯示分頁
更新我的問題,請參閱它 – Krasimir 2013-04-09 19:55:29
你在頁面loage綁定的GridView的IsPostBack裏面的!如果(!IsPostBack) getViewProfit();如果(!IsPostBack) void page-load() { } } – 2013-04-09 20:05:18