This is first time to do the web program with vwd 2008 express, just tried to practice to add an Insert button on gridview, actually the insert button not working yet.

MY QUESTION is when I connected the database with Access USING GRIDVIEW, if the Access table is empty, I could not see the gridview on the internet, but the table has some data, I would see the gridview on the internet, WHY? HOW TO FIX?

THANKS.

Dani AI

Generated

is right: the GridView will not render row output when the bound query returns zero rows, so you either need an EmptyDataTemplate (or EmptyDataText) or another technique to keep the grid visible and provide an Insert UI. The following shows concrete, practical options.

Simple EmptyDataTemplate (shows a message or a small form when the table is empty):

<asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1" AutoGenerateColumns="False">
  <Columns>
    <asp:BoundField DataField="ID" HeaderText="ID" />
    <asp:BoundField DataField="Name" HeaderText="Name" />
  </Columns>
  <EmptyDataTemplate>
    No records found. Use the form below to add one.
    <!-- You can place input controls and an Insert button here -->
  </EmptyDataTemplate>
</asp:GridView>

If a visible header (column headings) is required when there are no rows, the common pattern is to bind a dummy/empty row so GridView renders headers, then hide that fake row:

DataTable dt = GetDataFromAccess(); // your select logic
if (dt.Rows.Count == 0)
{
  dt.Rows.Add(dt.NewRow());      // preserve columns so header renders
  GridView1.DataSource = dt;
  GridView1.DataBind();
  GridView1.Rows[0].Visible = false; // hide fake row
}
else
{
  GridView1.DataSource = dt;
  GridView1.DataBind();
}

Notes on the Insert button not working: GridView does not auto-provide Insert; place controls in a FooterTemplate, EmptyDataTemplate, or use a separate form, then either set an AccessDataSource.InsertCommand with matching InsertParameters or handle the button click/RowCommand in code-behind to perform the INSERT and rebind. Also confirm the deployed Access file path and permissions on the host (App_Data path vs local), and check Visual Studio's DB copy settings so you are not overwriting the live .mdb on each debug build.

Recommended Answers

All 2 Replies

MY QUESTION is when I connected the database with Access USING GRIDVIEW, if the Access table is empty, I could not see the gridview on the internet, but the table has some data, I would see the gridview on the internet, WHY? HOW TO FIX?

THANKS.

Add your text/message in EmptyDataTemplate. EmptyDataTemplate will be shown when a datasource is empty.

Add your text/message in EmptyDataTemplate. EmptyDataTemplate will be shown when a datasource is empty.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.