简体   繁体   中英

Gridview without data

I have a gridview that has insert, update, and delete functionality. This gridview uses a datatable and dataadapter to bind data to the gridview once a postback has occured. Depending on my dropdownlist's that I have chosen, I may or may not have SQL records that show. When there is no data, it doesn't show the gridview at all, so I have no way to use the insert functionality on my gridview to start inserting rows.

My idea so far is to add a form (textboxes) that the user will enter the first record into a table, and after that, the gridview will show and they can use the insert function that I added into that. Is this a good approach? or is there a better way to do this.

You are correct that the gridview will not be displayed if there is no data in the datasource it's been bound to.

Alternatively you can define a <EmptyDataTemplate> as like below which will be displayed when there is no data to display. In this template you can instruct the user what to do (may be like what you're planning to do .. redirect to a new form upon button/link click)

<asp:GridView .. >

   <Columns>

      ....

   </Columns>

  <EmptyDataTemplate>
    <span style="font-size: 12px; font-weight: bold; color: Blue;">No records are available matching your selected filter. Click on "Add" button to enter new data .. </span>               
  </EmptyDataTemplate>

</asp:GridView>

If you want the grid header to be displayed when there is no data then you can set the below for the gridview definition.

ShowHeaderWhenEmpty="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM