我有一个gridview与BoundField列,我想插入一个新的行专门为这个BoundField。这是可能做到的吗?
代码如下:
<asp:GridView ID="grdAgreements" runat="server" AutoGenerateColumns="false" Width="100%"
AllowSorting="false" AlternatingRowStyle-BackColor="White"
HeaderStyle-BackColor="White" HeaderStyle-ForeColor="GrayText"
Font-Names="Arial" Font-Size="11" DataKeyNames="AgreementId" OnRowCreated="grdAgreements_RowCreated" >
<rowstyle height="24" />
<Columns>
<asp:BoundField HeaderText="Agreement Number" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="AgreementNumber" SortExpression="AgreementNumber" ItemStyle-Width="110" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="Description" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="Description" SortExpression="Description" ItemStyle-Width="100" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="Start Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="StartDate" SortExpression="StartDate" ItemStyle-Width="125" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="End Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="EndDate" SortExpression="EndDate" ItemStyle-Width="200" ItemStyle-Font-Names="Arial" />
<asp:BoundField HeaderText="Site Number" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="SiteNumber" SortExpression="SiteNumber" ItemStyle-Width="200" ItemStyle-Font-Names="Arial" />
</Columns>
<EmptyDataTemplate>
There are no agreements to display.
</EmptyDataTemplate>
</asp:GridView>
我想要发生的是,而不是BoundField我想有SiteNumber绑定到一个新的行,我可以粘贴在一个div或面板。我该怎么做呢?
让我知道,如果我不理解它的权利,但如果你想自定义字段的布局,你可以使用TemplateField而不是BoundField
<asp:TemplateField HeaderText="SiteNumber" SortExpression="SiteNumber">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("SiteNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
但是如果你正在考虑将特定列移动到新行中,那么你将不得不查看其他数据绑定控件,如ListView或Repeater,因为GV标记不是可自定义的
按照通常的时间限制,我没有通过并找出使用Listview的最佳方法来满足我的需求,但我确实找到了一种方法来获得我正在寻找的布局,在TemplateField和ItemTemplate中使用样式表。下面的代码是我想出的,希望这将有助于其他人寻找类似的解决方案。如果你没有时间限制,我强烈建议你进一步研究一下Listview控件。附注:我使用的css是一个巨大的PITA,让所有的样式完美,但我认为这绝对是值得的。这些都在GridView中BTW
<asp:TemplateField>
<ItemTemplate>
<div class="EquipmentTable1" >
<table >
<tr>
<td>
Customer Equipment
</td>
<td>
Contract
</td>
<td >
Contract Number
</td>
<td>
Modality
</td>
</tr>
<tr>
<td>
<%--TODO link this to the customer equipment record pulled from the services web portal guide part 1 document--%>
<a href="../Agreements/AgreementList.aspx?CustomerEquipmentID=<%# Eval("CustomerEquipmentID") %>"><%# Eval("CustomerEquipmentID") %> </a>
</td>
<td >
<%--Link to the agreement page and
pass in the agreement id as a query string to do a lookup of the agreement--%>
<a href="../Agreements/AgreementView.aspx?AgreementID=<%# Eval("AgreementID") %>"><%# Eval("AgreementID") %></a>
</td>
<td>
<%# Eval("AgreementLineID") %>
</td>
<td>
<%# Eval("ModalityID") %>
</td>
</tr>
</table>
</div>
<div class="EquipmentTable2" >
<table >
<tr>
<td>
Product
</td>
<td >
Model Number
</td>
<td>
Room Number
</td>
<td>
Date Installed
</td>
</tr>
<tr>
<td >
<%# Eval("Product") %>
</td>
<td>
<%# Eval("ModelNumber") %>
</td>
<td>
<%# Eval("RoomNumber") %>
</td>
<td>
<%# Eval("DateInstalled") %>
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>