【问题标题】:Empty data in Gridview , rows not showingGridview 中的空数据,行不显示
【发布时间】:2015-07-15 06:51:56
【问题描述】:

我有一个 GridView,其中 5 列包含数据,两列为空。还有一个编辑按钮,我可以编辑每一行。只有在我按下按钮编辑并将数据添加到表单并完成后,这两列才会不再为空。我怎样才能做到这一点 ? 我尝试使用“无数据”的 EmptyDataText,但它不起作用。

我的 GridView 没有显示包含空数据的行。

我正在使用 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>

这是我的 GridView。只有Referent和Nr Form会先为空。

【问题讨论】:

  • 提供一些代码来展示你已经拥有的东西
  • 没有代码没有人可以帮助你。请出示您的代码。

标签: c# asp.net


【解决方案1】:

在您的gridview 中添加ShowHeaderWhenEmpty="true"

注意:除非DataBind() 被调用,否则标题不会出现 不是 null 的东西。

【讨论】:

  • 是的,我知道,但我不想只显示标题。我想显示所有字段以及在编辑后第一个为空的两个字段,并向表单添加一些内容以填充
  • 在您编辑列并向其中添加数据后,它将显示。其实你的问题不清楚。您能否更具体地说明您的问题或问题。
猜你喜欢
  • 2011-10-26
  • 2013-12-16
  • 2013-12-10
  • 1970-01-01
  • 2016-10-16
  • 2014-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多