<asp:GridView ID="GridView1" runat="server" AllowPaging="True" CssClass="dx"

onpageindexchanging="GridView1_PageIndexChanging" ondatabound="GridView1_DataBound"

AutoGenerateColumns="False" onrowcommand="GridView1_RowCommand1">

<PagerSettings PageButtonCount = "5" Mode="NumericFirstLast" />

<PagerTemplate>

<div style="text-align:center">

<asp:ImageButton ID="btnFirst" ImageUrl="~/images/btn_home.gif" CommandName="Page" CommandArgument="First" runat="server" CausesValidation="false" />

<asp:ImageButton ID="btnPrev" ImageUrl="~/images/btn_prev.gif" CommandName="Page" CommandArgument="Prev" runat="server" CausesValidation="false" />

<asp:LinkButton ID="btnNum1" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum2" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum3" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum4" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum5" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum6" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum7" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum8" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum9" runat="server" CommandName="Page" CausesValidation="false" />

<asp:LinkButton ID="btnNum10" runat="server" CommandName="Page" CausesValidation="false" />

<asp:ImageButton ID="btnNext" ImageUrl="~/images/btn_next.gif" CommandName="Page" CommandArgument="Next" runat="server" CausesValidation="false" />

<asp:ImageButton ID="btnLast" ImageUrl="~/images/btn_end.gif" CommandName="Page" CommandArgument="Last" runat="server" CausesValidation="false" />

</div>

</PagerTemplate>

<EmptyDataTemplate>검색결과가존재하지않습니다</EmptyDataTemplate>

</asp:GridView>

 

이걸 넣어준다..

CommandName은 꼭! 저거로 해야하고.. 그렇지 않으면 페이징처리가 안된다..

CommandArgument는 이게 어떤 방식으로 될건지 정해주는건데..

거의 이건 몇페이지에 갈것인지를 묻는것이니.. 패스~

 

 PageButtonCount = "5" 이부분은 이 페이지버튼이 몇개나 나올것인가 하는것을 정해준것이다..

 

이렇게해놓게되면.. 내가 6페이지를 보고있을 때

<<  <  6  7  8  9  10  >  >>

이렇게 버튼이 나온다..(그림이 이상한가..-_-;)

 

그리고 이제 비하인드코드에..PageIndexChanging 이벤트를 만들고 그안에 식을 넣어주어야 한다..

 

//버튼들초기에는안보이게하기나중에필요할때보여주기

Control btn;

for (int i = 1; i <= 10; i++)

{

btn = pagerRow.Cells[0].FindControl("btnNum" + i);

btn.Visible = false

}

ImageButton btnPrevList = (ImageButton)pagerRow.Cells[0].FindControl("btnPrev");

btnPrevList.Visible = false

ImageButton btnFirst = (ImageButton)pagerRow.Cells[0].FindControl("btnFirst");

btnFirst.Visible = false

ImageButton btnLast = (ImageButton)pagerRow.Cells[0].FindControl("btnLast");

btnLast.Visible = false

ImageButton btnNext = (ImageButton)pagerRow.Cells[0].FindControl("btnNext");

btnNext.Visible = false

 

//카운터세팅

int pageCount = gv.PageCount;

int pageIndex = gv.PageIndex + 1;

int pageButtonCount = gv.PagerSettings.PageButtonCount;//페이지버튼몇개만들건가설정해둔것가져오기

int lastPage = pageButtonCount;//마지막페이지부분은

if (pageCount < lastPage)

{ lastPage = pageCount; }

 

int first = 1;

int last = lastPage;

if (pageIndex > last)

{

first = gv.PageIndex / pageButtonCount * pageButtonCount + 1;

last = first + pageButtonCount - 1;

if (last > pageCount)

{ last = pageCount; }

if (last - first + 1 < pageButtonCount)

{ first = Math.Max(1, last - pageButtonCount + 1); }

}

//다시보여주기

//첫페이지가보여져야한다면

if (first != 1)

{

btnPrevList.Visible = true

 

int t = first - 1;

btnPrevList.CommandArgument = t.ToString();

 

btnFirst.Visible = true

 

}

int count = 1;

for (int i = first; i <= last; i++, count++)

{

string str = i.ToString();

LinkButton numButton = (LinkButton)pagerRow.Cells[0].FindControl("btnNum" + count);

numButton.Visible = true

if (i == pageIndex)

{

numButton.Text = str;

numButton.Enabled = false

}

else

{

numButton.Text = str;

numButton.CommandArgument = str;

}

}

 

if (pageCount > last)

{

btnNext.Visible = true

int t = last + 1;

btnNext.CommandArgument = t.ToString();

 

btnLast.Visible = true

 

}

 


+ Recent posts