title: How to show gridview footer which is bounded by table columns and table is empty ? ASP.NET C#
body: <p>I'm working on my SQL project,I have created a gridview in which I bound the values in gridview footer according to table columns. </p>
  
  <p>Basically, I'm creating a gridview in which user insert values and create a table. But, I'm facing a problem when the table contains 'One' record or more than one record then it's working fine, but I want that when table empty then footer of gridview show which contains "textboxes", "checkboxes" and "dropdownlist".</p>
  
  <p>When table contains one record then this gridview show, it's working fine, here is </p>
  
  <p><a href="https://i.stack.imgur.com/uHlkm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uHlkm.png" alt="image"></a> </p>
  
  <p>When table contains no data then this gridview show </p>
  
  <p><a href="https://i.stack.imgur.com/ElmYW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ElmYW.png" alt="image"></a></p>
  
  <p>How can I show this type of gridview </p>
  
  <p><a href="https://i.stack.imgur.com/uHlkm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uHlkm.png" alt="image"></a> </p>
  
  <p>when the table has no data so that user insert values and create table?</p>
  
  <p>Here is my ASPX markup:</p>
  
  <pre><code> &lt;asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True" 
      AutoGenerateColumns="False" BackColor="#DEBA84"
      BorderColor="#DEBA84"  BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
       ShowFooter="True" Style="margin-left: 136px; margin-top: 72px;
      margin-right: 0px;" Height="16px" Width="685px" 
       DataSourceID="sql"&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField HeaderText="Column_Name" SortExpression="Column_Name"&gt;
              &lt;EditItemTemplate&gt;
                   &lt;asp:TextBox ID="txtName" runat="server" Text='&lt;%# Bind("Column_Name") %&gt;'&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator Text="*" ID="colname" ControlToValidate="txtName"
                      runat="server" ErrorMessage="Column Name is Required" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Column_Name") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:TextBox ID="txtColName" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:RequiredFieldValidator ValidationGroup="INSERT" Text="*" ID="insertcolname" ControlToValidate="txtColName"
                      runat="server" ErrorMessage="Column Name is Required" ForeColor="Red"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
             &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Data_Type" SortExpression="Data_Type"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='&lt;%# Bind("Data_Type") %&gt;'&gt;
                      &lt;asp:ListItem&gt;Select Datatype&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;int&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Float&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(50)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(100)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;double&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:RequiredFieldValidator ID="datatype" ControlToValidate="DropDownList1"
                      runat="server" ErrorMessage="Data Type is Required" ForeColor="Red" InitialValue="Select Datatype"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("Data_Type") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
              &lt;FooterTemplate&gt;
                  &lt;asp:DropDownList ID="DropDownList2" runat="server"&gt;
                      &lt;asp:ListItem&gt;Select Datatype&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;int&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Float&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(50)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;Varchar(100)&lt;/asp:ListItem&gt;
                      &lt;asp:ListItem&gt;double&lt;/asp:ListItem&gt;
                  &lt;/asp:DropDownList&gt;
                  &lt;asp:RequiredFieldValidator ValidationGroup="INSERT" Text="*"  ID="datatype" ControlToValidate="DropDownList2"
                      runat="server" ErrorMessage="Data Type is Required" ForeColor="Red" InitialValue="Select Datatype"&gt;
                  &lt;/asp:RequiredFieldValidator&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Allow_Null_" SortExpression="Allow_Null_"&gt;
                                  &lt;EditItemTemplate&gt;
                                      &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem,"Allow_Null_")) %&gt;'/&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# Convert.ToBoolean(DataBinder.Eval(Container.DataItem,"Allow_Null_"))%&gt;' enabled="false" /&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;FooterTemplate&gt;
                                      &lt;asp:CheckBox ID="nulll" runat="server" /&gt;
                                  &lt;/FooterTemplate&gt;
                              &lt;/asp:TemplateField&gt;
                              &lt;asp:TemplateField HeaderText="Primary_Key_" SortExpression="Primary_Key_"&gt;
                                  &lt;EditItemTemplate&gt;
                                      &lt;asp:CheckBox ID="CheckBox2" runat="server" Checked='&lt;%# Convert.ToBoolean(DataBinder.Eval(Container.DataItem,"Primary_Key_")) %&gt;' /&gt;
                                  &lt;/EditItemTemplate&gt;
                                  &lt;ItemTemplate&gt;
                                      &lt;asp:CheckBox ID="CheckBox2" runat="server" 
                                          Checked='&lt;%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem,"Primary_Key_")) %&gt;' Enabled="false" /&gt;
                                  &lt;/ItemTemplate&gt;
                                  &lt;FooterTemplate&gt;
                                      &lt;asp:CheckBox ID="primary" runat="server" /&gt;
                                  &lt;/FooterTemplate&gt;
                              &lt;/asp:TemplateField&gt;
  
          &lt;asp:CommandField ShowEditButton="True" /&gt;
          &lt;asp:CommandField ShowDeleteButton="True" /&gt;
  
          &lt;asp:TemplateField HeaderText="Insert"&gt;
          &lt;FooterTemplate&gt;
  
  
               &lt;asp:LinkButton ValidationGroup="INSERT" ID="LinkButton1" runat="server" OnClick="lbinssert"&gt;INSERT&lt;/asp:LinkButton&gt;
              &lt;/FooterTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
  
      &lt;/Columns&gt;
      &lt;FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /&gt;
      &lt;HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /&gt;
      &lt;PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /&gt;
      &lt;RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /&gt;
      &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#FFF1D4" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#B95C30" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#F1E5CE" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#93451F" /&gt;
        &lt;/asp:GridView&gt;
  
  &lt;asp:ValidationSummary ValidationGroup="INSERT" ID="ValidationSummary1" ForeColor="Red"
      runat="server" Height="25px" style="margin-left: 140px" /&gt;
      &lt;br /&gt;
  &lt;input type="submit" style="position:relative; width:30px; left:452px; top: 0px; width: 86px;" 
       value="Create table" name="create"/&gt;
  &lt;asp:ValidationSummary ID="ValidationSummary2" ForeColor="Red" runat="server" 
      style="margin-left: 142px" /&gt;
      &lt;asp:SqlDataSource ID="sql" runat="server" 
       ConnectionString="&lt;%$ ConnectionStrings:db_compilerConnectionString %&gt;" 
  
       SelectCommand="SELECT [Column_Name], [Data_Type], [Allow_Null_], [Primary_Key_], [Date] FROM [tbl_field]"
       DeleteCommand="DELETE  FROM [tbl_field] WHERE [Field_id]=@field" InsertCommand="INSERT INTO [tbl_field] ([Column_Name],[Data_Type],[Database_id],[Allow_Null_],[Primary_Key_])Values (@ColumnName,@Dtype,@id,@null,@primary)"
       UpdateCommand="UPDATE [tbl_field] SET [Column_Name]=@ColumnName,[Data_Type]=@Dtype,[Database_id]=@id,[Allow_Null_]=@null,[Primary_Key_]=@primary"&gt;
       &lt;DeleteParameters&gt;
       &lt;asp:Parameter Name="field" Type="Int32" /&gt;
       &lt;/DeleteParameters&gt;
       &lt;InsertParameters&gt;
       &lt;asp:Parameter Name="ColumnName" Type="String" /&gt;
        &lt;asp:Parameter Name="Dtype" Type="String" /&gt;
         &lt;asp:Parameter Name="id" Type="String" /&gt;
          &lt;asp:Parameter Name="null" Type="Boolean" /&gt;
           &lt;asp:Parameter Name="primary" Type="Boolean" /&gt;
  
  
       &lt;/InsertParameters&gt;
       &lt;UpdateParameters&gt;
        &lt;asp:Parameter Name="ColumnName" Type="String" /&gt;
        &lt;asp:Parameter Name="Dtype" Type="String" /&gt;
         &lt;asp:Parameter Name="id" Type="String" /&gt;
          &lt;asp:Parameter Name="null" Type="Boolean"/&gt;
           &lt;asp:Parameter Name="primary" Type="Boolean" /&gt;
  
       &lt;/UpdateParameters&gt;
  
   &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Here is my aspx.cs code: </p>
  
  <pre><code>public void lbinssert(Object sender,EventArgs e)
  {
      sql.InsertParameters["ColumnName"].DefaultValue =
          ((TextBox)GridView1.FooterRow.FindControl("txtColName")).Text;
      sql.InsertParameters["Dtype"].DefaultValue =
          ((DropDownList)GridView1.FooterRow.FindControl("DropDownList2")).Text;
      sql.InsertParameters["id"].DefaultValue =
         ((DropDownList)GridView1.FooterRow.FindControl("DropDownList2")).Text;
      sql.InsertParameters["null"].DefaultValue =
        ((CheckBox)GridView1.FooterRow.FindControl("nulll")).Checked == true ? "true" : "false";
      sql.InsertParameters["primary"].DefaultValue = ((CheckBox)GridView1.FooterRow.FindControl("primary")).Checked == true ? "true" : "false";
  
      sql.Insert();
     }
  </code></pre>