Liudi Wijaya
Liudi Wijaya

Reputation: 956

Add Row Count in Caption of Gridview ASP.NET

How to add row count information in gridview caption? I write this code in design source. But it not work.

<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="WindowFrame" Caption="Number of records: <%# gvData.Rows.Count %>">

Upvotes: 1

Views: 258

Answers (1)

vahid tajari
vahid tajari

Reputation: 1303

You should use OnDataBound event:

protected void gvData_OnDataBound(object sender, EventArgs e)
        {
            gvData.Caption = $"Number of records:{gvData.Rows.Count.ToString()}";
        }

Upvotes: 1

Related Questions