gpt4 book ai didi

c# - GridView PageIndexChanging 不工作

转载 作者:行者123 更新时间:2023-11-30 21:16:09 30 4
gpt4 key购买 nike

这似乎是一个很容易问的问题,但我无法在 GridView 中显示项目。这是我的代码:

 public partial class TestList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{ TestProject.DataAccess.Repository.Instance.Initialize(Settings.Default.TestConnection);
BindData();
}

}

private void BindData()
{
//Restriction Info!!
gvAgentList.DataSource = EntityRegistration.DataAccess.Repository.Instance.GetData();
gvAgentList.DataBind();
}

protected void gvAgentList_PageIndexChanging (object sender, GridViewPageEventArgs e)
{

gvAgentList.PageIndex = e.NewPageIndex;
gvAgentList.DataBind();
}

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;

switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}

protected void gvAgentList_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = gvAgentList.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

gvAgentList.DataSource = dataView;
gvAgentList.DataBind();
}
}

}

这是 GridView 的标记:

    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<p>
Agent Lists:</p>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView runat ="server" ID = "gvAgentList"
AllowPaging = "True"
AutoGenerateSelectButton="True" AllowSorting="True" BackColor="#E8E8E8"
BorderColor="#003399" BorderStyle="Solid" BorderWidth="1px" Height="375px"
Width="731px" OnPageIndexChanging = "gvAgentList_PageIndexChanging"
OnSorting="gvAgentList_Sorting" >

<AlternatingRowStyle ForeColor="#0066CC" />
<HeaderStyle ForeColor="#3366FF" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>



</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

问题是我的 GridView 没有向我抛出任何异常,通过断点我可以看到该函数是在代码后面调用的。

My sorting is also not working :(

最佳答案

尝试

protected void gvAgentList_PageIndexChanging (object sender, GridViewPageEventArgs e)
{

gvAgentList.PageIndex = e.NewPageIndex;
BindData();
}

关于c# - GridView PageIndexChanging 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5382477/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com