0

我正在使用一个grid view我提供两个选项,

  1. 如果您在数据库中有数据,它将显示在edit template
  2. 如果没有数据footer template,将 b 显示entering new data

    但是当我尝试第二点时,空白编辑模板也会显示在带有编辑按钮的页脚行上方,请建议我在没有数据时如何隐藏该编辑模板。

我的代码是

设计:

 <asp:GridView ID="gvNavigationDtls" runat="server" AutoGenerateColumns="False" SkinID="GridView"
                                        AlternatingRowStyle-CssClass="gridAltRow" RowStyle-CssClass="gridRow" ShowFooter="True"
                                        EditRowStyle-CssClass="gridEditRow" FooterStyle-CssClass="gridFooterRow">
                                        <AlternatingRowStyle CssClass="gridAltRow" />
                                        <Columns>
                                            <asp:TemplateField HeaderText="OBSERVATION CODE" HeaderStyle-HorizontalAlign="Left"
                                                ControlStyle-Width="150px">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtCode" runat="server" Text='<%# Bind("code_name") %>' Width="150px"></asp:TextBox>
                                                    <asp:ImageButton ID="imgbtnCode" runat="server" Height="20px" ImageAlign="AbsMiddle"
                                                        ImageUrl="~/Images/openFolder.png" OnClientClick="ShowSearch('Code',this); return false;"
                                                        TabIndex="5" Width="20px" />
                                                    <asp:HiddenField ID="hdnCodeCd" runat="server" Value='<%# Bind("NAV_DEF_CODE_CD") %>' />
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtCode" runat="server" Width="150px"></asp:TextBox>
                                                    <asp:ImageButton ID="imgbtnCode" runat="server" Height="20px" ImageAlign="AbsMiddle"
                                                        ImageUrl="~/Images/openFolder.png" OnClientClick="ShowSearch('Code',this); return false;"
                                                        TabIndex="5" Width="20px" />
                                                    <asp:HiddenField ID="hdnCodeCd" runat="server" />
                                                </FooterTemplate>
                                                <ItemTemplate>
                                                    <%--<asp:Label ID="lblCode" runat="server" Text='<%# Bind("code_name") %>'></asp:Label>--%>
                                                    <%# Eval("code_name")%>
                                                </ItemTemplate>
                                                <ControlStyle Width="150px" />
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="DESCRIPTION" HeaderStyle-HorizontalAlign="Left" ControlStyle-Width="150px">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtDescription" runat="server" Text='<%# Bind("OBSERVATION") %>'
                                                        Width="150px" TextMode="MultiLine"></asp:TextBox>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtDescription" runat="server" Width="150px" TextMode="MultiLine"></asp:TextBox>
                                                </FooterTemplate>
                                                <ItemTemplate>
                                                    <%# Eval("OBSERVATION")%>
                                                </ItemTemplate>
                                                <ControlStyle Width="150px" />
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="STATUS" HeaderStyle-HorizontalAlign="Left" ControlStyle-Width="80px">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtStatus" runat="server" Text='<%# Bind("OBS_STATUS") %>' Width="80px"></asp:TextBox>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtStatus" runat="server" Width="80px"></asp:TextBox>
                                                </FooterTemplate>
                                                <ItemTemplate>
                                                    <%# Eval("OBS_STATUS")%>
                                                    <%--      <%# Eval("NAV_OBS_DTL_CD")%>--%>
                                                </ItemTemplate>
                                                <ControlStyle Width="80px" />
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
                                                <EditItemTemplate>
                                                    <asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="True" CommandName="Update"
                                                        Text="Update" OnClientClick="return confirm('Update?')" ValidationGroup="Update"></asp:LinkButton>
                                                    <asp:ValidationSummary ID="vsUpdate" runat="server" ShowMessageBox="true" ShowSummary="false"
                                                        ValidationGroup="Update" Enabled="true" HeaderText="Validation Summary..." />
                                                    <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                                        Text="Cancel"></asp:LinkButton>
                                                    <asp:HiddenField ID="hdnNavObsDtlCd" runat="server" Value='<%# Bind("NAV_OBS_DTL_CD") %>' />
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="True" CommandName="Insert"
                                                        ValidationGroup="Insert" Text="Insert"></asp:LinkButton>
                                                    <asp:ValidationSummary ID="vsInsert" runat="server" ShowMessageBox="true" ShowSummary="false"
                                                        ValidationGroup="Insert" Enabled="true" HeaderText="Validation..." />
                                                    <asp:HiddenField ID="hdnNavObsDtlCd" runat="server" Value='<%# Bind("NAV_OBS_DTL_CD") %>' />
                                                </FooterTemplate>
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit"
                                                        Text="Edit"></asp:LinkButton>
                                                    <asp:HiddenField ID="hdnFlag" runat="server" Value='<%# Bind("Flag") %>' />
                                                </ItemTemplate>
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                        </Columns>
                                        <EditRowStyle CssClass="gridEditRow" />
                                        <EmptyDataTemplate>
                                            <table class="grid" cellspacing="0" rules="all" border="1" id="gvNavigationDtls"
                                                style="border-collapse: collapse;">
                                                <tr>
                                                    <th align="left" scope="col">
                                                        Observation Code
                                                    </th>
                                                    <th align="left" scope="col">
                                                        Description(initial comm.)
                                                    </th>
                                                    <th align="left" scope="col">
                                                        Status
                                                    </th>
                                                    <th align="left" scope="col">
                                                    </th>
                                                </tr>
                                                <tr class="gridRow">
                                                    <td colspan="8">
                                                        No Records found...
                                                    </td>
                                                </tr>
                                                <tr class="gridFooterRow">
                                                    <td>
                                                        <asp:TextBox ID="txtCode" runat="server" MaxLength="6"></asp:TextBox>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtDescription" runat="server"></asp:TextBox>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtStatus" runat="server"></asp:TextBox>
                                                    </td>
                                                    <td colspan="2" align="justify" valign="middle">
                                                        <asp:LinkButton ID="lnkAdd" runat="server" CausesValidation="false" CommandName="emptyInsert"
                                                            Text="emptyInsert"></asp:LinkButton>
                                                    </td>
                                                </tr>
                                            </table>
                                        </EmptyDataTemplate>
                                        <FooterStyle CssClass="gridFooterRow" />
                                        <RowStyle CssClass="gridRow" />
                                    </asp:GridView>

在页脚中添加空行的功能:

 private void ShowNoResultFound(DataTable source, GridView gv)
    {
 source.Columns.Add("code_name");
        source.Columns.Add("OBSERVATION");
        source.Columns.Add("OBS_STATUS");
        source.Columns.Add("Flag");
        source.Rows.Add(source.NewRow()); // create a new blank row to the DataTable
        // Bind the DataTable which contain a blank row to the GridView
        gv.DataSource = source;
        gv.DataBind();
4

1 回答 1

0

ShowNoResultFound检查长度后 调用gvNavigationDtls。尝试这个

if(gvNavigationDtls.Rows.Count == 0)
{
  // show the footer
}
于 2013-02-06T07:15:54.357 回答