i have a gridview that should split into pages but the issue is that when i change the page the whole gridview is disapearing i tried evrything i found in the internet but with no solution here is my code
我有一个gridview应该分成页面,但问题是,当我改变页面时,整个gridview消失了我试过evrything我在互联网上找到但没有解决方案这里是我的代码
<asp:GridView ID="ExistContents" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"
AllowPaging="true" PageSize="5" OnPageIndexChanging="ExistContents_PageIndexChanging" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="ContentID" HeaderText="id" />
<asp:ImageField DataImageUrlField="TmpFilename" HeaderText="Image">
<ControlStyle Height="64px" Width="96px" />
</asp:ImageField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="Type" HeaderText="Type" />
<asp:BoundField DataField="ContentID" HeaderText="id" Visible="false" ShowHeader="false" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:CheckBox runat="server" ID="ChBox1" OnCheckedChanged="ExistContents_CheckedChanged" AutoPostBack="True"/>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" CssClass="header"/>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
and here is the event handler
这是事件处理程序
protected void ExistContents_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
ExistContents.PageIndex = e.NewPageIndex;
List<CONTENT> panier;
panier = (List<CONTENT>)Session["PANIER"];
ExistContents.DataSource = panier;
ExistContents.DataBind();
}
thanks for your help
谢谢你的帮助
2 个解决方案
#1
0
You should handle the PageIndexChanged
event instead.
您应该处理PageIndexChanged事件。
The pageIndexChanging
is made to give you an option to cancel the paging before it's executed.
pageIndexChanging用于为您提供在执行之前取消分页的选项。
#2
0
here is an answer for this probleme, acctually my datasource was not the session but a linq query so i changed it and it works perfectly
这里是这个问题的答案,实际上我的数据源不是会话而是linq查询所以我改变它并且它完美地工作
and here is my new code
这是我的新代码
protected void ExistContents_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow gr = (GridViewRow)chk.Parent.Parent.Parent.Parent;
int id= Convert.ToInt32(gr.Cells[0].Text);
if (chk.Checked)
AddToCaddy(id, "DELETE");
else
DeleteFromCaddy(id);
UpdatePanel.DataBind();
UpdatePanel.Update();
}
just for information if you are making a databind to your gridview in the Page_Load inside the if (!IsPostBack)
then you will need to redefind the dataSource but if you'r not then you only need to use these functions
只是为了获取信息,如果你在if(!IsPostBack)里面的Page_Load中为你的gridview创建一个数据绑定,那么你需要重新修改dataSource,但如果你没有,那么你只需要使用这些函数
UpdatePanel.DataBind(); UpdatePanel.Update();
i hope this helps
我希望这有帮助
#1
0
You should handle the PageIndexChanged
event instead.
您应该处理PageIndexChanged事件。
The pageIndexChanging
is made to give you an option to cancel the paging before it's executed.
pageIndexChanging用于为您提供在执行之前取消分页的选项。
#2
0
here is an answer for this probleme, acctually my datasource was not the session but a linq query so i changed it and it works perfectly
这里是这个问题的答案,实际上我的数据源不是会话而是linq查询所以我改变它并且它完美地工作
and here is my new code
这是我的新代码
protected void ExistContents_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow gr = (GridViewRow)chk.Parent.Parent.Parent.Parent;
int id= Convert.ToInt32(gr.Cells[0].Text);
if (chk.Checked)
AddToCaddy(id, "DELETE");
else
DeleteFromCaddy(id);
UpdatePanel.DataBind();
UpdatePanel.Update();
}
just for information if you are making a databind to your gridview in the Page_Load inside the if (!IsPostBack)
then you will need to redefind the dataSource but if you'r not then you only need to use these functions
只是为了获取信息,如果你在if(!IsPostBack)里面的Page_Load中为你的gridview创建一个数据绑定,那么你需要重新修改dataSource,但如果你没有,那么你只需要使用这些函数
UpdatePanel.DataBind(); UpdatePanel.Update();
i hope this helps
我希望这有帮助