4
我已經打開了我的gridview上的分頁,但是當我嘗試更改頁面時,回發數據回來爲空。尋呼無法正常工作
第一次加載頁面時,數據就在那裏。
這是我第一次做這個,所以我可能做錯了什麼。
該數據源是一個membershipusercollection列表。
這裏是我的代碼...
protected void Page_Load(object sender, EventArgs e)
{
count = 0;
switch (Request.QueryString["status"])
{
case "active":
lblUserListTitle.Text = "Activated user accounts";
break;
case "inactive":
lblUserListTitle.Text = "Inactive user accounts";
break;
case "locked":
lblUserListTitle.Text = "Locked user accounts";
break;
case "online":
lblUserListTitle.Text = "Users online";
break;
case "notverified":
lblUserListTitle.Text = "Users accounts not yet verified";
break;
default:
lblUserListTitle.Text = "All user accounts";
break;
}
if (!IsPostBack)
BindGrid();
lblSearchResult.Text = "There are " + count.ToString() + " registered users found.";
}
protected void BindGrid()
{
MembershipUserCollection usersList = Membership.GetAllUsers();
MembershipUserCollection filteredUsers = new MembershipUserCollection();
foreach (MembershipUser user in usersList)
{
if (!Roles.IsUserInRole(user.UserName, "Admin") && !Roles.IsUserInRole(user.UserName, "Engineering"))
{
userProfile = Profile.GetProfile(user.UserName);
if (txtFilterCustomerNo.Text.Length > 0)
{
ProfileCommon PC = Profile.GetProfile(user.UserName);
if (PC.RaymarineAccountNo == txtFilterCustomerNo.Text.ToUpper())
{
filteredUsers.Add(user);
count++;
}
}
else
{
//filter on querystring
if (Request.QueryString["status"] == "active")
{
if (user.IsApproved && !user.IsLockedOut)
{
filteredUsers.Add(user);
count++;
}
}
else if (Request.QueryString["status"] == "inactive")
{
if (!user.IsApproved && !user.IsLockedOut)
{
filteredUsers.Add(user);
count++;
}
}
else if (Request.QueryString["status"] == "locked")
{
if (user.IsLockedOut)
{
filteredUsers.Add(user);
count++;
}
}
else if (Request.QueryString["status"] == "online")
{
if (user.IsOnline)
{
filteredUsers.Add(user);
count++;
}
}
else if (Request.QueryString["status"] == "notverified")
{
if (user.IsApproved && !userProfile.IsVerified)
{
filteredUsers.Add(user);
count++;
}
}
else
{
filteredUsers.Add(user);
count++;
}
}
}
}
GridView1.DataSource = filteredUsers;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
}
,並在.aspx頁面...
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="1000px" onrowdatabound="GridView1_RowDataBound" ViewStateMode="Enabled" AllowPaging="True" onpageindexchanging="GridView1_PageIndexChanging" PageSize="25">
<Columns>
<asp:TemplateField ItemStyle-Width="70px">
<ItemTemplate>
<asp:HyperLink ID="lnkProfile" runat="server"><asp:Image ID="Image3" runat="server" ImageUrl="~/Content/admin_miniProfile.png" AlternateText="User Profile" /></asp:HyperLink>
<asp:HyperLink ID="lnkPermissions" runat="server"><asp:Image ID="Image2" runat="server" ImageUrl="~/Content/admin_miniPermissions.png" AlternateText="Permissions" /></asp:HyperLink>
<asp:HyperLink ID="lnkPassword" runat="server"><asp:Image ID="Image1" runat="server" ImageUrl="~/Content/admin_miniResetPassword.png" AlternateText="Reset Password" /></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:TemplateField ItemStyle-Width="100px" HeaderText="Account No">
<ItemTemplate>
<asp:Label ID="lblAccountNo" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CreationDate" HeaderText="Created" ItemStyle-Width="160px" />
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<asp:HyperLink ID="lnkSalesman" runat="server"><asp:Image ID="imgFilter" runat="server" ImageUrl="~/Content/admin_miniFilter.png" /></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="200px" HeaderText="Salesman">
<ItemTemplate>
<asp:Label ID="lblSalesman" runat="server" Text=""></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="20px">
<ItemTemplate>
<asp:HyperLink ID="lnkDelete" runat="server"><asp:Image ID="Image4" runat="server" ImageUrl="~/Content/admin_miniDeleteUser.png" AlternateText="Delete User" /></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Position="TopAndBottom" />
<RowStyle Height="20px" VerticalAlign="Middle" />
<AlternatingRowStyle BackColor="#EEEEEE" />
</asp:GridView>
一切工作除了分頁罰款。
任何人都可以幫助我嗎?請讓我知道,如果我錯過了任何重要的信息,我會更新!
創建數據源(業務層)並將其綁定到datagrid。如果正確完成,你不需要在cs文件裏面有一行代碼。 –