我有像这样的网格视图
<asp:GridView ID="gridBranchTiming" EmptyDataText="No Records Found" runat="server" AutoGenerateColumns="False" BorderWidth="0"
AllowPaging="true" PageSize="15" Width="100%" OnPageIndexChanging="gridBranchTiming_PageIndexChanging"
CssClass="mGrid" OnRowDeleting="gridBranchTiming_RowDeleting"
OnRowCommand="gridBranchTiming_RowCommand" OnRowCreated="gridBranchTiming_RowCreated" >
<AlternatingRowStyle CssClass="alt" />
<PagerStyle CssClass="pgr" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<th rowspan="2">#</th>
<th rowspan="2">Branch ID</th>
<th rowspan="2">From</th>
<th rowspan="2">To</th>
<th colspan="2">Sunday </th>
<th colspan="2">Monday </th>
<th colspan="2">Tuesday </th>
<th colspan="2">Wednesday </th>
<th colspan="2">Thursday </th>
<th colspan="2">Friday </th>
<th colspan="2">Saturday </th>
<th rowspan="2">Edit</th>
<th rowspan="2">Delete</th>
<tr>
<th></th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<td><%# Container.DataItemIndex + 1 %></td>
<td><%#Eval("BranchID") %></td>
<td><%#Eval("fromDate") %></td>
<td><%#Eval("toDate") %></td>
<td><%#Eval("SundayIn") %></td>
<td><%#Eval("SundayOut") %></td>
<td><%#Eval("MondayIn") %></td>
<td><%#Eval("MondayOut") %></td>
<td><%#Eval("TuesdayIn") %></td>
<td><%#Eval("TuesdayOut") %></td>
<td><%#Eval("WednesdayIn") %></td>
<td><%#Eval("WednesdayOut") %></td>
<td><%#Eval("ThursdayIn") %></td>
<td><%#Eval("ThursdayOut") %></td>
<td><%#Eval("FridayIn") %></td>
<td><%#Eval("FridayOut") %></td>
<td><%#Eval("SaturdayIn") %></td>
<td><%#Eval("SaturdayOut") %></td>
<td>
<a class="aEdit" title="Edit" href='EditBranchTiming.aspx?Id=<%#Eval("BranchTimeEntryID") %>'>Edit</a>
</td>
<td>
<asp:LinkButton ID="lnkDelete" CssClass="aDelete" ToolTip="Delete" runat="server" CommandName="delete" OnClientClick=' javascript:return confirm("Are you sure you want to delete?"); '
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "BranchTimeEntryID") %>'>Delete</asp:LinkButton>
</td>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
但是当它在浏览器中呈现时,我的网格中会附加一个额外的空列。我无法弄清楚那个空行是如何追加的。
这是输出的样子
检查时的
和浏览器代码是
<table class="mGrid" cellspacing="0" rules="all" id="ContentPlaceHolder1_gridBranchTiming" style="border-width:0px;width:100%;border-collapse:collapse;">
<tbody><tr>
<th scope="col">
</th><th rowspan="2">#</th>
<th rowspan="2">Branch ID</th>
<th rowspan="2">From</th>
<th rowspan="2">To</th>
<th colspan="2">Sunday </th>
<th colspan="2">Monday </th>
<th colspan="2">Tuesday </th>
<th colspan="2">Wednesday </th>
<th colspan="2">Thursday </th>
<th colspan="2">Friday </th>
<th colspan="2">Saturday </th>
<th rowspan="2">Edit</th>
<th rowspan="2">Delete</th>
</tr><tr>
<th></th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
</tr>
<tr>
<td>
</td><td>1</td>
<td>NBAD004</td>
<td>18/02/2015</td>
<td>24/02/2015</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>
<a class="aEdit" title="Edit" href="EditBranchTiming.aspx?Id=6">Edit</a>
</td>
<td>
<a onclick=" javascript:return confirm("Are you sure you want to delete?"); ;" id="ContentPlaceHolder1_gridBranchTiming_lnkDelete_0" title="Delete" class="aDelete" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gridBranchTiming$ctl02$lnkDelete','')">Delete</a>
</td>
</tr><tr class="alt">
<td>
</td><td>2</td>
<td>NBAD004</td>
<td>01/01/2014</td>
<td>31/12/2014</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>00:00</td>
<td>11:00</td>
<td>14:00</td>
<td>00:00</td>
<td>00:00</td>
<td>
<a class="aEdit" title="Edit" href="EditBranchTiming.aspx?Id=1019">Edit</a>
</td>
<td>
<a onclick=" javascript:return confirm("Are you sure you want to delete?"); ;" id="ContentPlaceHolder1_gridBranchTiming_lnkDelete_1" title="Delete" class="aDelete" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gridBranchTiming$ctl03$lnkDelete','')">Delete</a>
</td>
</tr>
</tbody></table>
任何想法摆脱那个空栏????
答案 0 :(得分:0)
这是一个非常难看的黑客,它将解决您的问题。
$(document).ready(function(){
$("table.mGrid th:first-child").remove();
$("table.mGrid td:first-child").remove();
});
但你必须真正使用像这样的ListView。
<asp:ListView ID="ListView1" runat="server" DataKeyNames="job_id" DataSourceID="SqlDataSource1">
<LayoutTemplate>
<table>
<thead>
<tr runat="server">
<th rowspan="2">#</th>
<th rowspan="2">Branch ID</th>
<th rowspan="2">From</th>
<th rowspan="2">To</th>
<th colspan="2">Sunday </th>
<th colspan="2">Monday </th>
<th colspan="2">Tuesday </th>
<th colspan="2">Wednesday </th>
<th colspan="2">Thursday </th>
<th colspan="2">Friday </th>
<th colspan="2">Saturday </th>
<th rowspan="2">Edit</th>
<th rowspan="2">Delete</th>
</tr>
<tr>
<th></th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
<th>From</th>
<th>To</th>
</tr>
</thead>
<tbody>
<tr runat="server" id="itemPlaceholder" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Container.DataItemIndex + 1 %></td>
<td><%#Eval("BranchID") %></td>
<td><%#Eval("fromDate") %></td>
<td><%#Eval("toDate") %></td>
<td><%#Eval("SundayIn") %></td>
<td><%#Eval("SundayOut") %></td>
<td><%#Eval("MondayIn") %></td>
<td><%#Eval("MondayOut") %></td>
<td><%#Eval("TuesdayIn") %></td>
<td><%#Eval("TuesdayOut") %></td>
<td><%#Eval("WednesdayIn") %></td>
<td><%#Eval("WednesdayOut") %></td>
<td><%#Eval("ThursdayIn") %></td>
<td><%#Eval("ThursdayOut") %></td>
<td><%#Eval("FridayIn") %></td>
<td><%#Eval("FridayOut") %></td>
<td><%#Eval("SaturdayIn") %></td>
<td><%#Eval("SaturdayOut") %></td>
<td>
<a class="aEdit" title="Edit"
href='EditBranchTiming.aspx?Id=<%#Eval("BranchTimeEntryID") %>'>Edit</a>
</td>
<td>
<asp:LinkButton ID="lnkDelete" runat="server"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "BranchTimeEntryID") %>'
CommandName="delete"
CssClass="aDelete"
ToolTip="Delete"
OnClientClick=' javascript:return confirm("Are you sure you want to delete?"); '>Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
ASP.NET框架引入了asp:ListView
,以便为生成的标记提供更大的灵活性。另一种方法是像这样使用GridView
s RowCreated
事件
链接:https://stackoverflow.com/a/18327885/17447