GridView.Row.Count always 0, How to solve?
<p>I am new in ASP.NET. I use a GridView. When I Count rows of GridView, it shows 0 always. I am giving code. But when I run the code browser, It shows data. How solve this problem?</p>

<p>My CS code is: </p>

<pre><code>protected void btnSend_OnClick(object sender, EventArgs e)
    {
        string MemberList= (ViewState["Memberlist"]).ToString();
        List&lt;PreparedEmail&gt; preparedEmail = new List&lt;PreparedEmail&gt;();
        Utility util = new Utility();
        int count = 0;

        int i1 = dlClients.Rows.Count; // it shows always 0
        #region Send Invitation
        foreach (GridViewRow mail in dlClients.Rows)
        {
          //some code here, It is never execute as dlClients.Rows shows 0
         }                            
}
</code></pre>

<p>My aspx code is : </p>

<pre><code>&lt;asp:GridView ID="dlClients" EnableViewState="false" runat="server" AutoGenerateColumns="False" ClientIDMode="Static" GridLines="None" AllowPaging="false" CssClass="table table-bordered table-striped" OnPreRender="dlClients_PreRender" DataKeyNames="MemberId" PageSize="10" ShowHeader="true"&gt; 
</code></pre>

<p>And My data binding code:</p>

<pre><code>Protected void dlClients_PreRender(object sender, EventArgs e)
    {
        List&lt;CircleUser&gt; memberList = new CircleUserBusinessLogic().GetAll();
        dlClients.DataSource = memberList;

        dlClients.DataBind();
        //GridUpdatePanel.Update();
        ViewState["Memberlist"] = memberList;

        if (dlClients.Rows.Count &gt; 0)
        {
            //Replace the &lt;td&gt; with &lt;th&gt; and adds the scope attribute
            dlClients.UseAccessibleHeader = true;

            //Adds the &lt;thead&gt; and &lt;tbody&gt; elements required for DataTables to work
            dlClients.HeaderRow.TableSection = TableRowSection.TableHeader;

            //Adds the &lt;tfoot&gt; element required for DataTables to work
            dlClients.FooterRow.TableSection = TableRowSection.TableFooter;
        }
    }
</code></pre>