How to define number of rows of GridView at runtime in code behind using C#
<p>I need to develop such a program in which the GridView's rows should be decided at run time.</p>

<p>i.e. I have a table in database called dealer capacity.</p>

<p>Dealer_ID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    Capacity<br>
D0001 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;            5  </p>

<p>Now when the Dealer D00001 is selected from combo box the number of rows in grid view should be 5. I want to use the template field also.</p>

<p>My code for GridView is:</p>

<pre><code>&lt;asp:GridView ID="grdlicence" runat="server" DataKeyNames="Version_id" GridLines="None" BorderStyle="Solid" AutoGenerateColumns="false" AllowSorting="true"     
        CssClass="mGrid table" 
        PagerStyle-CssClass="pgr" 
        AlternatingRowStyle-CssClass="alt" &gt;
             &lt;Columns&gt;
                 &lt;asp:BoundField DataField="Version_name" ItemStyle-CssClass="uppercase" ItemStyle-Width="150px"   HeaderText="Version" HeaderStyle-HorizontalAlign="Left" /&gt;

                &lt;asp:BoundField DataField="Version_id" Visible="false" HeaderText="Version" HeaderStyle-HorizontalAlign="Left" /&gt;

              &lt;asp:TemplateField HeaderText="Price"&gt;
                &lt;ItemTemplate&gt;
                       &lt;center&gt;&lt;asp:TextBox ID="txtprice" CssClass="alignments TextStyle" MaxLength="5"  runat="server" &gt;&lt;/asp:TextBox&gt;&lt;/center&gt;
                &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;

              &lt;asp:TemplateField HeaderText="Licence Id"&gt;
                &lt;ItemTemplate&gt;
                       &lt;center&gt;&lt;asp:TextBox ID="txtlicenceid" CssClass="alignments uppercase"  runat="server" &gt;&lt;/asp:TextBox&gt;&lt;/center&gt;
                &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;


              &lt;asp:TemplateField HeaderText="Purchase Date"&gt;
                &lt;ItemTemplate&gt;
                       &lt;center&gt;&lt;asp:TextBox ID="txtpurchasedate"  onfocus="showCalendarControl(this);"  CssClass="alignments TextStyle"   runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/center&gt;
                &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;


              &lt;asp:TemplateField HeaderText="Expiry Date"&gt;
                &lt;ItemTemplate&gt;
                       &lt;center&gt;&lt;asp:TextBox ID="txtexpirydate"  onfocus="showCalendarControl(this);"  CssClass="alignments TextStyle"   runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/center&gt;
                &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;

                 &lt;asp:TemplateField HeaderText="Upload File"&gt;
                &lt;ItemTemplate&gt;
                     &lt;center&gt;&lt;asp:FileUpload ID="fileUpload" runat="server"  /&gt;&lt;/center&gt; 
                &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;


           &lt;/Columns&gt;

           &lt;/asp:GridView&gt;
</code></pre>
