I have a ASP.NET GridView which I want to display a series of textBoxs in when the gridView is empty so the user can add more data. Functionally it all works but when it renders it appears to have an extra row between the headers and my row of textBoxs.
我有一个ASP。我想在GridView为空时显示一系列文本框,以便用户添加更多数据。从功能上讲,它都可以工作,但当它呈现时,它会在标题和我的textBoxs行之间出现额外的行。
<table class="grid" cellspacing="0" rules="all" border="1" id="ContentPlaceHolder1_gridViewReferences" style="border-collapse:collapse;">
<tr>
<th align="left" scope="col" style="width:50px;">Id</th><th align="left" scope="col">Reference</th><th align="left" scope="col" style="width:400px;">Source</th><th align="left" scope="col" style="width:50px;">Edit</th><th align="left" scope="col" style="width:50px;">Delete</th>
</tr><tr>
<td colspan="5">
<tr style="background-color: #E8ECED;">
<td>
<span style="display:inline-block;width:50px;">0</span>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$gridViewReferences$ctl02$textBoxReference" type="text" id="ContentPlaceHolder1_gridViewReferences_textBoxReference" class="ZenStyle" style="width:100%;" />
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$gridViewReferences$ctl02$textBoxSource" type="text" id="ContentPlaceHolder1_gridViewReferences_textBoxSource" class="ZenStyle" style="width:400px;" />
</td>
<td>
<a id="ContentPlaceHolder1_gridViewReferences_LinkButton1" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gridViewReferences$ctl02$LinkButton1','')" style="display:inline-block;width:50px;">Insert</a>
<div id="ContentPlaceHolder1_gridViewReferences_ValidationSummary1" style="display:none;">
</div>
</td>
<td></td>
</tr>
</td>
</tr>
</table>
When I examine the rendered HTML there is indeed an extra row but I can't workout how to either add my textBoxs to it or remove it. My .aspx code for the grid...I've not included the code behind or the styling as I don't think it's relevant.
当我检查呈现的HTML时,确实有一个额外的行,但是我无法计算如何添加或删除文本框。我的。aspx网格代码…我没有包含代码或样式,因为我认为它不相关。
<asp:GridView ID="gridViewReferences" runat="server" AutoGenerateColumns="False" CssClass="grid" EnableViewState="false"
AlternatingRowStyle-CssClass="gridAltRow" RowStyle-CssClass="gridRow" ShowFooter="True"
EditRowStyle-CssClass="gridEditRow" FooterStyle-CssClass="gridFooterRow" OnRowCancelingEdit="gridViewReferences_RowCancelingEdit"
OnRowCommand="gridViewReferences_RowCommand" OnRowDataBound="gridViewReferences_RowDataBound" OnRowDeleting="gridViewReferences_RowDeleting"
OnRowEditing="gridViewReferences_RowEditing" OnRowUpdating="gridViewReferences_RowUpdating" DataKeyNames="Id" ShowHeaderWhenEmpty="true">
<Columns>
<%--ID column ( which also acts as the key )--%>
<asp:TemplateField HeaderText="Id" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle Width="50" />
<ItemStyle Width="50" />
<ItemTemplate>
<%# Eval("Id")%>
</ItemTemplate>
</asp:TemplateField>
<%--Reference column--%>
<asp:TemplateField HeaderText="Reference" HeaderStyle-HorizontalAlign="Left">
<EditItemTemplate>
<asp:TextBox Width="100%" ID="textBoxReference" runat="server" Text='<%# Bind("Reference") %>' CssClass="ZenStyle"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox Width="100%" ID="textBoxReference" runat="server" CssClass="ZenStyle"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<%# Eval("Reference") %>
</ItemTemplate>
</asp:TemplateField>
<%--Source column--%>
<asp:TemplateField HeaderText="Source" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle Width="400" />
<ItemStyle Width="400" />
<EditItemTemplate>
<asp:TextBox Width="100%" ID="textBoxSource" runat="server" Text='<%# Bind("Source") %>' CssClass="ZenStyle"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Width="100%" ID="lblEmail" runat="server" Text='<%# Eval("Source")%>' CssClass="ZenStyle" />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox Width="100%" ID="textBoxSource" runat="server" CssClass="ZenStyle" />
</FooterTemplate>
</asp:TemplateField>
<%--Edit / Update column--%>
<asp:TemplateField HeaderText="Edit" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle Width="50" />
<ItemStyle Width="50" />
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="false" CommandName="Update2"
Text="Update" ValidationGroup="Update"></asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</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..." />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<%--Delete column--%>
<asp:TemplateField HeaderText="Delete" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
<HeaderStyle Width="50" />
<ItemStyle Width="50" />
<ItemTemplate>
<asp:Button ID="lnkDelete" runat="server" CausesValidation="False" CommandName="Delete" CssClass="myButton"
Text="Delete" OnClientClick="return confirm('Delete?')"></asp:Button>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<tr style="background-color: #E8ECED;">
<td>
<asp:Label Width="50px" runat="server">0</asp:Label>
</td>
<td>
<asp:TextBox Width="100%" ID="textBoxReference" runat="server" Text='<%# Bind("Reference") %>' CssClass="ZenStyle"></asp:TextBox>
</td>
<td>
<asp:TextBox Width="400px" ID="textBoxSource" runat="server" Text='<%# Bind("Source") %>' CssClass="ZenStyle"></asp:TextBox>
</td>
<td>
<asp:LinkButton Width="50px" ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert" ValidationGroup="Insert" Text="Insert"></asp:LinkButton>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="Insert" Enabled="true" HeaderText="Validation..." />
</td>
<td></td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
1 个解决方案
#1
1
You can work around with this
你可以用这个
<EmptyDataRowStyle CssClass="EmptyDataClass" />
<EmptyDataTemplate>
...
</EmptyDataTemplate>
And in your css :
在css中:
.EmptyDataVacancyClass {
display: none;
}
#1
1
You can work around with this
你可以用这个
<EmptyDataRowStyle CssClass="EmptyDataClass" />
<EmptyDataTemplate>
...
</EmptyDataTemplate>
And in your css :
在css中:
.EmptyDataVacancyClass {
display: none;
}