I am trying to create a Gridview that allows me to add to a database. I think I have the Gridview formatted correctly and I do not want to use the <emptydatarowstyle>. I have been playing around with different solutions to displaying a header and footer in a gridview with no data in it all day. I beleive I am REALLY close but cant seem to bring it together and have it show so please a point in the right direction would be much appreciated. I will attach my gridview control as well as my code.

<asp:GridView ID="PurchaseOrderOfficeEquipmentGridView"
    backcolor="#F1F1F1"
    DataSourceID="SQLPurchaseOrdersDataSource"
    DataKeyNames="PROPERTY_ID"
    ShowFooter="True"
    ShowHeader="true"
    runat="server"
    >
        <Columns>
            <asp:TemplateField HeaderText="Office Equipment">
                <ItemTemplate>
                    <asp:Label ID="lblOfficeEQ" Text='<%# eval("PURCHASE_ORDER_OFFICE_EQUIPMENT") %>' runat="server"></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPO_Office_EQ" Text='<%# eval("PURCHASE_ORDER_OFFICE_EQUIPMENT") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtPO_Office_EQ" runat="server"></asp:TextBox>
                </FooterTemplate>
                
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Price">
                <ItemTemplate>
                    <asp:Label ID="lblOfficePR" Text='<%# eval("PURCHASE_ORDER_OFFICE_PRICE") %>' runat="server"></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPO_Office_PR" Text='<%# eval("PURCHASE_ORDER_OFFICE_PRICE") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtPO_Office_PR" runat="server"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="Quantity">
                <ItemTemplate>
                    <asp:Label ID="lblOfficeQU" Text='<%# eval("PURCHASE_ORDER_OFFICE_QUANTITY") %>' runat="server"></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPO_Office_QU" Text='<%# eval("PURCHASE_ORDER_OFFICE_QUANTITY") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>            
                <FooterTemplate>
                    <asp:TextBox ID="txtPO_Office_QU" runat="server"></asp:TextBox>
                </FooterTemplate>            
            </asp:TemplateField>
            
            <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                        <asp:LinkButton ID="linkDeleteCust" CommandName="Delete" runat="server">Delete</asp:LinkButton>
                    </ItemTemplate>
                <FooterTemplate>
                    <asp:LinkButton ID="linkAddRow" CommandName="AddRow"  runat="server">+Add</asp:LinkButton>
                </FooterTemplate>
                </asp:TemplateField>
        
            
        </Columns>
    </asp:GridView>
Imports System.Data

Partial Class GridView
    Inherits System.Web.UI.Page



    Public Sub CheckEmptyGrid(ByVal dv As DataView)
        Try

            Dim ds As DataSet = New DataSet()
            Dim dt As DataTable = dv.Table
            ds.Tables.Add(dt)
            If ds.Tables(0).Rows.Count = 0 Then
                ds.Tables(0).Rows.Add(ds.Tables(0).NewRow())
                PurchaseOrderOfficeEquipmentGridView.DataSource = ds
                PurchaseOrderOfficeEquipmentGridView.DataBind()

                Dim columnCount = PurchaseOrderOfficeEquipmentGridView.Rows(0).Cells.Count
                PurchaseOrderOfficeEquipmentGridView.Rows(0).Cells.Clear()
                PurchaseOrderOfficeEquipmentGridView.Rows(0).Cells.Add(New TableCell())
                PurchaseOrderOfficeEquipmentGridView.Rows(0).Cells(0).ColumnSpan = columnCount
                PurchaseOrderOfficeEquipmentGridView.Rows(0).Cells(0).Text = "Add Records"

            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dssa As New DataSourceSelectArguments
        CheckEmptyGrid(SQLPurchaseOrdersDataSource.Select(dssa))
    End Sub
End Class

What are the benifits of a ListView? I am not opposed toward either one I just have had a bit more experiance with the GridView and also some of the articles I have been reading through are focused mainly on the Gridview. Also thank you for the link i never thought of using my SQL to SELECT a blank row like that... your a life saver! :)

Victory at last!! AHAHA. After 3 days of reading countless articles on overriding constructors for the gridview and all sorts of hackish methods of making this thing work I FINALLY found a nice clean (and I mean REALLY clean) way of making this work! All you need to do is use your select statement to pull in dummy data. From there you can fire an OnRowDataBound event and check if the data is infact your dummy data. If it is set your row.visible = false and Voila, done. Header and footer still appear... dummy data is gone... we all win! :D These are the moments that remind me why I program...forgive the exuberance! here is the code:


FROM SQL DATA SOURCE:

SelectCommand="SELECT '' as [PURCHASE_ORDER_ID], '' as [PURCHASE_ORDER_OFFICE_EQUIPMENT], '' as [PURCHASE_ORDER_OFFICE_PRICE], '' as [PURCHASE_ORDER_OFFICE_QUANTITY] UNION SELECT * FROM [PURCHASE_ORDER_OFFICE_EQUIPMENT] "

FROM GRIDVIEW CONTROL

<asp:GridView ID="PurchaseOrderOfficeEquipmentGridView"
    backcolor="#F1F1F1"
    DataSourceID="SQLPurchaseOrdersDataSource"
    DataKeyNames="PURCHASE_ORDER_ID"
    ShowFooter="True"
    runat="server" AutoGenerateColumns="False"
    OnRowDataBound="GV_DataBound"
       
    >

From CodeBehind:

Protected Sub GV_DataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow Then 
            Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView)
            If CType(drv("PURCHASE_ORDER_ID"), Int32) = 0 Then
                e.Row.Visible = False
            End If
        End If
    End Sub

Nice work. Thanks. It does work. I felt I must reply since daniweb deletes old topics.

Nice work. Thanks. It does work. I felt I must reply since daniweb deletes old topics.

Glad to hear it worked for you. Dani Web is a great place for any issue you have with your ASP.net. If you have any more questions regarding gridview/detailsview or any other control for that matter don't hesitate to PM me. I do a lot of custom gridview integrations and extensions so I am very familiar with the issues of the control.

Nice work. Thanks. It does work. I felt I must reply since daniweb deletes old topics.

(cough) Erm, no DaniWeb does not delete old topics...

Thank you got the help i nedded from this article

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.