0

Gridview Controlラベル テンプレート フィールドを含む があります。ラベル値は、RowDataBound 中に埋められます。このテンプレートフィールド以外のページネーションを行うと、すべてページネーションされます。ページネーションを行うと、ラベルテンプレートフィールドが埋められるたびにRowDataBound.

今はできませんpagination。助けてください

これは私のコードです

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" OnDataBound="GridView1_DataBound" OnPageIndexChanging="GridView1_PageIndexChanging1" OnRowDataBound="GridView1_RowDataBound1" PageSize="3">
                    <Columns>
                        <asp:TemplateField HeaderText="First Row">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server">Text</asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="White" ForeColor="#000066" />
                    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                    <RowStyle ForeColor="#000066" />
                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#007DBB" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#00547E" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>

GridView.cs

protected void Page_Load(object sender, EventArgs e)
        {
            Getdata();
        }

        public void Getdata()
        {
            SqlConnection con = new SqlConnection("Data Source=CMH-SOSQL\\SQ1;Initial Catalog=RPT2020_DEV;Integrated Security=True");
            con.Open();
            string qry = "use PID2020_DEV select * from batch_void_rsn_cd";
            SqlDataAdapter da = new SqlDataAdapter(qry, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();    
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridView1.Columns[0].HeaderText = "First Row";
                Label lblKey = (Label)e.Row.FindControl("Label1");
                lblKey.Text = e.Row.RowIndex.ToString();
            }
        }

        protected void GridView1_DataBound(object sender, EventArgs e)
        {

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            Getdata(); 
        }
4

1 に答える 1