0

グリッドビューのページングを許可しようとしています。グリッドビューでページングを許可し、ページサイズも追加しました。残念ながら、うまくいきません。私が調査したところ、コードを追加する必要がない人を見てきました。

これは私のグリッドビューのソースコードです

<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();
4

2 に答える 2

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();
}
于 2013-07-19T06:56:12.370 に答える
0

グリッドビューの PageIndexChanging イベントを処理する必要があります。

例えば:

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

bindGrid メソッドには、グリッドをバインドするためのコードが含まれます。例えば

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();
    }
于 2013-07-19T07:10:40.697 に答える