VS 2013,VB。 ASP.NET
我的网页上有一个gridview。
<asp:GridView ID="gvSteam" runat="server" AutoGenerateColumns="False" CssClass="gvSteam">
<Columns>
<asp:BoundField DataField="Generation" HeaderText="Steam Generation (Capacity)" ReadOnly="True" SortExpression="DisplayName" />
<asp:TemplateField HeaderText="TPH" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="lblValueEnergy" runat="server" Text='<%# Format8888(Eval("Power")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
</asp:GridView>
背后的代码如下
Dim Asset As New Assets
Dim Allsteam As New List(Of Assets)
Allsteam = Asset.GetSteamGenerated()
gvSteam.DataSource = Allsteam
gvSteam.DataBind()
我想在某个点(例如第4行之后)在gridview中添加一个空行,并为其添加一些文本。
我可以使用数据表的示例,但我使用的是gridview,并且更喜欢这样做。
答案 0 :(得分:0)
使用以下内容对其进行排序,可能不是最佳方式,但可行。
Dim newRow As GridViewRow
For Each newRow In gvSteam.Rows
If newRow.RowIndex = 3 Then
Dim row As New GridViewRow(4, 4, DataControlRowType.EmptyDataRow, DataControlRowState.Normal)
Dim tc As New TableCell
tc.ColumnSpan = 2
Dim lbl As New Label
tc.Controls.Add(lbl)
lbl.Text = "Steam Turbine 11"
row.Controls.Add(tc)
gvSteam.Rows(4).Parent.Controls.AddAt(4, row)
End If
Next