Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:59:10+00:00 2026-05-25T14:59:10+00:00

I have this page with a GridView control inside that’s bound to database. GridView

  • 0

I have this page with a GridView control inside that’s bound to database. GridView has a command row for insert, delete and updating. The problem is that, since my database table is initially empty, I see an empty grid. I don’t even see the command row in order to be able to insert anything into it.
I managed to solve this by checking for GridView row count and changing its display to InsertTemplate. But I’m wondering if there’s a standard way of doing this, may it already has such functionality?
The same problem with DetailView.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:59:11+00:00Added an answer on May 25, 2026 at 2:59 pm

    You can use the EmptyDataTemplate to handle inserting a new item if the grid’s data source is initially empty.

    Define your grid in the ASPX as follows:

    <asp:GridView runat="server" ID="grid" AutoGenerateColumns="false" 
         OnRowCommand="grid_RowCommand">
        <Columns>
            <asp:ButtonField ButtonType="Link" CommandName="Add" Text="Add" />
            <asp:BoundField DataField="Id" HeaderText="Id" />
            <asp:BoundField DataField="FirstName" HeaderText="First Name" />
            <asp:BoundField DataField="LastName" HeaderText="Last Name" />
        </Columns>
        <EmptyDataTemplate>
            <asp:TextBox ID="CustomerFirstName" runat="server"></asp:TextBox><br />
            <asp:TextBox ID="CustomerLastName" runat="server"></asp:TextBox><br />
            <asp:Button ID="Save" Text="Save" runat="server" CommandName="EmptyAdd" 
                UseSubmitBehavior="False" />
        </EmptyDataTemplate>
    </asp:GridView>
    

    A collection of Customer objects is used as the datasource for the grid.

    public class Customer
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    

    Bind the grid to a data source (empty for this example).

    protected void Page_Load(object sender, EventArgs e)
    {
       var customers = new List<Customer> {};
        grid.DataSource = customers;
        grid.DataBind();
    }
    

    You can then handle the Add and EmptyAdd command in the grid_RowCommand event handler.

    protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EmptyInsert")
        {
        }
        if (e.CommandName == "Insert")
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Setup: I currently have a page with a GridView control on it inside
I have a gridview control with delete asp:ImageButton for each row of the grid.
I'm pretty new to this. I have an ASP gridview control so that in
My Gridview won't page or sort. By this I mean that the data in
I have a GridView control setup like this: <asp:GridView ID=UserList AllowPaging=True PageSize=20 runat=server> ...
I have an ASP.NET page with a gridview control on it with a CommandButton
I have developed an asp.net control that inherits from the gridview and its called
I have a gridview control that i am manually binding the data in. When
I have a custom control that is based off the gridview control located at:
I have a custom gridview control that extends the standard asp.net gridview control. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.