티스토리 뷰

💼 정보 ver1.0

ListView & DataPager & PagerCss

James Wetzel 2011. 2. 22. 20:01

----------------------------.aspx
<style>
.PagerNormal
{
    font: 6pt Verdana;
    color: #666;
    border: solid 1px #778899;
    padding: 1px 4px;  
    text-decoration:none;
    margin-right:4px;
}
.PagerCurrent
{
    font: 6pt Verdana;
    border: solid 1px #778899;
    padding: 1px 4px;
    background-color: #FFD700;       
    margin-right:4px;   
}
.PagerNextL
{
 vertical-align:middle;
 padding-right:7px;
}
.PagerNextR
{
 vertical-align:middle;
 padding-left:7px;
}
.PagerLayOut
{  
    text-align:center;   
    padding:10px;
    width:540px;
    margin-bottom:5px;
}
</style>
 <asp:ListView ID="userOpinion_LV" runat="server"
        onpagepropertieschanged="userOpinion_LV_PagePropertiesChanged">
        <ItemTemplate>
            <div class="comment2">
                <div>
                    <span class="info1">가꾸미 &nbsp;&nbsp;  | &nbsp;&nbsp;  <%# Eval("registerDate") %> &nbsp;&nbsp; | &nbsp;&nbsp; <img src='/Images/Thema/Star/<%# Eval("appraisal") %>.gif'</span>
                    <span class="info2"><a href="#">delete</a><a href="#">modify</a></span>
                </div>
                <p class="info_txt"><%# Eval("opinion") %></p>
            </div>
        </ItemTemplate>
    </asp:ListView>

<div class="PagerLayOut">
        <asp:DataPager runat="server" ID="ContactsDataPager"
            PagedControlID="userOpinion_LV" PageSize="1">
            <Fields>
 <asp:TemplatePagerField>             
            <PagerTemplate>
            <b>
            Page
            <asp:Label runat="server" ID="CurrentPageLabel"
              Text="<%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %>" />
            of
            <asp:Label runat="server" ID="TotalPagesLabel"
              Text="<%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>" />
            (
            <asp:Label runat="server" ID="TotalItemsLabel"
              Text="<%# Container.TotalRowCount%>" />
            records)
            <br />
            </b>
            </PagerTemplate>
          </asp:TemplatePagerField>
             <asp:NextPreviousPagerField ButtonCssClass="PagerNext" ButtonType="Image"
                    FirstPageImageUrl="~/Images/Thema/arrow_l1.gif" ShowFirstPageButton="True"
                    ShowNextPageButton="False"
                    PreviousPageImageUrl="~/Images/Thema/arrow_l2.gif" />
            <asp:NumericPagerField               
                    CurrentPageLabelCssClass="PagerCurrent"
                    NumericButtonCssClass="PagerNormal" ButtonCount="2" NextPageText="" PreviousPageText=""
                    RenderNonBreakingSpacesBetweenControls="False"/>
             <asp:NextPreviousPagerField ButtonCssClass="PagerNext" ButtonType="Image"
                    LastPageImageUrl="~/Images/Thema/arrow_r1.gif"
                    NextPageImageUrl="~/Images/Thema/arrow_r2.gif" ShowLastPageButton="True"
                    ShowPreviousPageButton="False" />
            </Fields>
        </asp:DataPager>
    </div>

--------------------- CS
 private void callUserOpinionList(int themaCategoryRegion_No)
        {
            Core.ThemaWeather tw = new Core.ThemaWeather();
            DataSet ds = tw.getUserOpinion(themaCategoryRegion_No);

            userOpinion_LV.DataSource = ds.Tables["ThemaCategoryRegionOpinion"];
            string[] keyNames = { "No" };
            userOpinion_LV.DataKeyNames = keyNames;           
            userOpinion_LV.DataBind();           
        } 
 /// <summary>
        /// 페이징 변경 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ThemaCategoryRegionUserRequest_LV_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            DataPager dp = (DataPager)ThemaCategoryRegionUserRequest_LV.FindControl("ThemaCategoryRegionUserRequest_LV_DataPager");
            if (dp != null)
            {
                dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            }

            callUserRequestList(State_DDL.SelectedValue, ThemaCategory_DDL.SelectedValue, SearchWord_TB.Text.Trim());
        }

        private void callUserRequestList(string state, string themaCategory, string searchWord)
        {
            Core.UserRequestManager urm = new Core.UserRequestManager();
            System.Data.DataSet ds = urm.getThemaCategoryRegionList(state, themaCategory, searchWord);

            ThemaCategoryRegionUserRequest_LV.DataSource = ds.Tables["ThemaCategoryRegion"];
            ThemaCategoryRegionUserRequest_LV.DataBind();
        }

/// <summary>
        /// 검색 버튼 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Search_IB_Click(object sender, ImageClickEventArgs e)
        {
            dataPagerReset();
            callUserRequestList(State_DDL.SelectedValue, ThemaCategory_DDL.SelectedValue, SearchWord_TB.Text.Trim());
        }
//DataPager 초기화
private void dataPagerReset()
        {
            DataPager dp = (DataPager)ThemaCategoryRegionUserRequest_LV.FindControl("ThemaCategoryRegionUserRequest_LV_DataPager");
            if (dp != null)
            {
                dp.SetPageProperties(0, dp.PageSize, false);
            }
        }

-------------결과



추가 정보 : http://msdn.microsoft.com/ko-kr/library/system.web.ui.webcontrols.templatepagerfield.aspx
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함