テンプレートフィールドを持つgridviewがあります。グリッドビューの最後の行は、正またはstring.empty(= null)の合計行です。アイデアは次のとおりです。合計行= nullの場合、どのようにしてグリッドビューの列を非表示にできますか? 効果は、値を持つ列のみが表示されるようにする必要があります。これは動的プロセスであるたびに入力(つまり1年)が異なる可能性があるためです。 テンプレートフィールドの例:GridView:テンプレートフィールドの列を動的に非表示にする方法
<asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:LinkButton ID="H3" runat="server" ToolTip="Milano-Sanremo" CommandName="Sort" CommandArgument="Milaan-San Remo DESC" Text="MSR" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="R3" runat="server" ToolTip="Milano-Sanremo" Text='<%# Eval("Milaan-San Remo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
私は分離コードの列を非表示にしようとした方法:
Dim TotalColumns As Integer
TotalColumns = GridView1.Rows(0).Cells.Count()
For i As Integer = 0 To TotalColumns - 1
If i > 4 Then
For Each row As TableRow In GridView1.Rows
If row.Cells(2).Text = "Nmbr of Riders" Then
Dim lid As String = DirectCast(row.FindControl("R3"), Label).Text
If lid = String.Empty Then
GridView1.Columns(i).Visible = True
Else
GridView1.Columns(i).Visible = False
End If
End If
Next
End If
Next
テキスト「ライダーのNmbrは」合計行を示しています。 R3は上記のテンプレートフィールドに対応します。コードは、GridviewのDataBoundイベントにあります。 私は他の多くのソリューションを試しましたが、何も役に立たないようです。 asp.netはテーブルのセルに値を見ないようですが、おそらく私は間違っています。 ご迷惑をおかけして申し訳ございません。