locked
make gridview appear with 0 rows RRS feed

  • Question

  • User-1767698477 posted

    How do I made a gridview appear when  0 rows are returned?  I just want the skeleton. I added a button on the gridview header to add a record on the fly. I need access to that.

    Thursday, May 13, 2021 2:56 AM

Answers

  • User-943250815 posted

    Try set Gridview property ShowHeaderWhenEmpty="True", this combined with at least Gridview.Databind (if bind is in code behind) or DataSource Control (sqldatasource, linqdatasource) will show it on page, other than gridview does not exist on page

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 13, 2021 11:42 AM

All replies

  • User-1545767719 posted

    My ct variable below is not doing the trick.

    What do you expect as ct and what is the result?

    Thursday, May 13, 2021 3:02 AM
  • User-1767698477 posted

    I got my row count fixed I think. I will know later after I add back a row. Right now the table has 0 rows.

    Thursday, May 13, 2021 3:09 AM
  • User-1545767719 posted

    Don't edit your question after response to it has been given. 

    Thursday, May 13, 2021 3:48 AM
  • User1535942433 posted

    Hi sking,

    How do I made a gridview appear when  0 rows are returned?  I just want the skeleton. I added a button on the gridview header to add a record on the fly. I need access to that.

    According to your description,I don't understand your meanings.Do you need a gridview only head? Is there a button in the head to add new row?

    Best regards,

    Yijing Sun

    Thursday, May 13, 2021 8:53 AM
  • User-943250815 posted

    Try set Gridview property ShowHeaderWhenEmpty="True", this combined with at least Gridview.Databind (if bind is in code behind) or DataSource Control (sqldatasource, linqdatasource) will show it on page, other than gridview does not exist on page

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 13, 2021 11:42 AM
  • User-1767698477 posted

    Thanks Jzero. Yes, I tried your suggestion and that does work for me. I only added the ShowHeaderWhenEmpty="True" to the gridview and it is working and showing the header row with my Add button to add a record.

     <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" CellPadding="3" HorizontalAlign="Center" OnRowDataBound="Gridview1_rowdatabound" DataKeyNames="LiabID" RowStyle-Wrap="False" HeaderStyle-Wrap="False" ShowHeaderWhenEmpty="True">

    Friday, May 14, 2021 12:10 AM