mihral
mihral

Reputation: 353

Empty data in Gridview , rows not showing

I have a GridView with 5 columns with data and two columns empty. And a button Edit which I can edit every row. Only after I push the Button Edit and add data to the form and finish the two columns will not be empty anymore. How can I do that ? I tried with EmptyDataText with "No data" but it doesn't work.

My GridView is not showing the rows with empty data.

I am using ASP.NET C#

<asp:GridView ID="GridViewSO" runat="server" DataSourceID="SqlDataSourceShippingOffice" AutoGenerateColumns="False" OnRowDataBound="GridViewSO_RowDataBound" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Font-Names="Calibri" Font-Size="8pt" EmptyDataText="No data" >
    <AlternatingRowStyle BackColor="#DCDCDC"></AlternatingRowStyle>
    <Columns>
        <asp:TemplateField HeaderText="Nr. crt.">
            <ItemTemplate>
                <%# Container.DataItemIndex + 1 %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="P_ID" HeaderText="P.ID" SortExpression="ID" />
        <asp:BoundField DataField="S_ID" HeaderText="S.ID" SortExpression="ID1" />
        <asp:BoundField DataField="DATE" HeaderText="Date" SortExpression="DATE" />
        <asp:BoundField DataField="PLACE" HeaderText="Place" SortExpression="PLACE" />
        <asp:BoundField DataField="DATE_U" HeaderText="DateU" SortExpression="DATE_U" />
        <asp:BoundField DataField="TYPE" HeaderText="Type" SortExpression="TYPE" />
        <asp:BoundField DataField="CAR" HeaderText="Car" SortExpression="CAR" />
        <asp:BoundField DataField="EH" HeaderText="EH" SortExpression="EH" />
        <asp:BoundField DataField="COND" HeaderText="Cond" SortExpression="COND" />
        <asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME" />
        <asp:BoundField DataField="REFERENT" HeaderText="Referent" ReadOnly="True" SortExpression="REFERENT" />
        <asp:TemplateField HeaderText="Nr Form">
            <ItemTemplate>
                <asp:TextBox ID="txtSOGV" runat="server" Enabled="False" Rows="4" TextMode="MultiLine" Style="overflow: auto" Height="45px" Width="64px"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="btnEditSO" runat="server" Text="Edit" OnClick="btnEditSO_Click" CausesValidation="False" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="ID" HeaderText="REF_ID" SortExpression="ID" />

    </Columns>
    <EmptyDataRowStyle BackColor="#CCCCFF" Font-Bold="True" ForeColor="#FF3300" />
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black"></FooterStyle>

    <HeaderStyle BackColor="#000084" Font-Bold="False" ForeColor="White" Font-Size="12pt"></HeaderStyle>

    <PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="Black"></PagerStyle>

    <RowStyle BackColor="#EEEEEE" ForeColor="Black"></RowStyle>

    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"></SelectedRowStyle>

    <SortedAscendingCellStyle BackColor="#F1F1F1"></SortedAscendingCellStyle>

    <SortedAscendingHeaderStyle BackColor="#0000A9"></SortedAscendingHeaderStyle>

    <SortedDescendingCellStyle BackColor="#CAC9C9"></SortedDescendingCellStyle>

    <SortedDescendingHeaderStyle BackColor="#000065"></SortedDescendingHeaderStyle>
</asp:GridView>

This is my GridView. And only the Referent and the Nr Form will be empty first.

Upvotes: 0

Views: 1183

Answers (1)

Litisqe Kumar
Litisqe Kumar

Reputation: 2564

Add ShowHeaderWhenEmpty="true" in your gridview

Note: the headers will not appear unless DataBind() is called with something other than null.

Upvotes: 1

Related Questions