2013-07-19 1 views
0

내 gridview에 대해 페이징을 허용하려고합니다. 나는 내 gridview에서 allowpaging을 가지고 페이지 크기를 추가했다. 불행히도, 그것은 작동하지 않습니다. 내가 조사한 결과 코드를 추가 할 필요가없는 사람들을 만났습니다.페이징을 사용하더라도 페이징을 사용할 수 없습니다.

이 내 gridview에

<asp:GridView ID="GVVerify" runat="server" AllowPaging="True" AutoGenerateSelectButton="True" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" CssClass="gridviewadminverify" ForeColor="Black" OnSelectedIndexChanged="GVVerify_SelectedIndexChanged" Width="100%"> 
       <FooterStyle BackColor="#CCCCCC" /> 
       <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> 
       <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" /> 
       <RowStyle BackColor="White" /> 
       <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /> 
       <SortedAscendingCellStyle BackColor="#F1F1F1" /> 
       <SortedAscendingHeaderStyle BackColor="#808080" /> 
       <SortedDescendingCellStyle BackColor="#CAC9C9" /> 
       <SortedDescendingHeaderStyle BackColor="#383838" /> 
      </asp:GridView> 

내 소스 코드이 내가 데이터 소스를 사용하여 다른 데이터 바인딩을 통해 내 SQL을 연결하는 방법입니다.

SqlConnection conn = new SqlConnection(); 
conn.ConnectionString = "Data Source = localhost; Initial Catalog = project; Integrated Security= SSPI"; 
conn.Open(); 

DataSet ds = new DataSet(); 

SqlDataAdapter da = new SqlDataAdapter("SELECT policeid as [Police ID], password as [Password], email as [Email], nric as [NRIC], fullname as [Full Name], contact as [Contact], address as [Address], location as [Location] From LoginRegisterPolice where pending='pending'", conn); 
da.Fill(ds); 

GVVerify.DataSource = ds;   
GVVerify.DataBind(); 
conn.Close(); 

답변

1

당신은 PageIndexChanging 이벤트를 사용하지 않는 당신은 PageIndexChanging 이벤트를 바인딩하고 현재 페이지를 사용하여 그리드를 바인딩해야합니다.

HTML을

<asp:GridView ID="GVVerify" runat="server" OnPageIndexChanging="GridViewPageEventHandler" AllowPaging="True" AutoGenerateSelectButton="True" BackColor="#CCCCCC" 
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" 
CssClass="gridviewadminverify" ForeColor="Black" OnSelectedIndexChanged="GVVerify_SelectedIndexChanged" 
Width="100%"> 

코드

protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GVVerify.PageIndex = e.NewPageIndex; 
    GVVerify.DataSource = GetGridData(); 
    GVVerify.DataBind(); 
} 
0

뒤에 당신은있는 gridview의 PageIndexChanging 이벤트를 처리해야합니다. 예

: bindGrid 방법 격자 결합의 코드를 포함 할

protected void GVVerify_PageIndexChanging(object sender, GridViewPageEventArgs e) 
    { 
     bindGrid(); 
     GVVerify.PageIndex = e.NewPageIndex; 
     GVVerify.DataBind(); 
    } 

. 예를 들면

private void bindGrid() 
    { 
     SqlConnection conn = new SqlConnection(); 
     conn.ConnectionString = "Data Source = localhost; Initial Catalog = project; Integrated Security= SSPI"; 
     conn.Open(); 
     DataSet ds = new DataSet(); 

     SqlDataAdapter da = new SqlDataAdapter("SELECT policeid as [Police ID], password as [Password], email as [Email], nric as [NRIC], fullname as [Full Name], contact as [Contact], address as [Address], location as [Location] From LoginRegisterPolice where pending='pending'", conn); 
     da.Fill(ds); 

     GVVerify.DataSource = ds;   
     GVVerify.DataBind(); 
     conn.Close(); 
    } 
관련 문제