DbEntry는 페이지 나누기 기술로 데이터를 GridView에 표시하고 AspNetPager 컨트롤로 페이지 나누기를 표시합니다

13927 단어 GridView
1. 백그라운드 코드
        protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RefreshViewer(1);
}
}
private void RefreshViewer(int NewIndex)
{
var ps = DbEntry
.From<User>()
.Where(Condition.Empty)
.OrderBy((DESC)"Id")
.PageSize(20)
.GetPagedSelector();
var count = ps.GetResultCount();

//Aspnetpager1 Properties Setting
AspNetPager1.RecordCount = Convert.ToInt32(count);
AspNetPager1.PageSize = 20;
AspNetPager1.UrlPaging = true;

NewIndex = NewIndex < 1 ? 1 : NewIndex;
//GridView Properties Setting
this.GridView1.PageSize = 20;
GridView1.DataKeyNames = new string[] { "Id"};
GridView1.PageIndex = NewIndex;
GridView1.DataSource = ps.GetCurrentPage(NewIndex-1);
GridView1.DataBind();
}

protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
RefreshViewer(e.NewPageIndex);
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Add Confirm messaged
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[2].Controls[0]).Attributes.Add("onclick",
"javascript:return confirm(' :"+ e.Row.Cells[1].Text + " ?')");
}
}
//Change Rows Mouceover and Mouceout Color
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString()+"";
User o = User.FindById(1);
o.Delete();

}

프론트 데스크 코드:
 
  <div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound"
OnRowDeleting="GridView1_RowDeleting">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Id" FooterText="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<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>
<br />
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText=" " LastPageText=" "
NextPageText=" " PrevPageText=" " Font-Names="Arial" AlwaysShow="true" ShowInputBox="Never"
CssClass="pages" CurrentPageButtonClass="cpb" UrlPaging="True" OnPageChanging="AspNetPager1_PageChanging"
HorizontalAlign="Center" PageSize="30">
</webdiyer:AspNetPager>
</div>

좋은 웹페이지 즐겨찾기