我正在使用 VB .NET,我有一个 GridView,它有 4 列(删除、下载、命名和 PK)。“名称”和“ID”列是我的 Sql 命令的结果,我想向用户隐藏“PK”列。但我做不到。我已经尝试了一些代码,但没有。
这是我的代码:
Public Sub obterTabela()
Dim db As DbConnect = New DbConnect()
Dim conn = New SqlConnection(db.geraConnString)
Dim cmd As New SqlCommand()
Dim aux As String = System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.Query)
aux = aux.Replace("?id=", "")
Dim conjunto As Integer = Convert.ToInt32(aux)
conn.Open()
'alterar
cmd = New SqlCommand("SELECT nome AS 'Nome', pk_table AS 'PK' FROM t_kml WHERE fk_table = " & aux, conn)
Dim dt As DataTable = New DataTable()
Dim sdr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
dt.Load(sdr)
'Dim indice As Integer = (Integer).Parse(dt.Columns("PK"))
'dt.Columns.Item("PK").ColumnMapping = MappingType.Hidden
sdr.Close()
gdv_kml.DataSource = dt
'gdv_kml.Columns(2).Visible = False
gdv_kml.DataBind()
End Sub
和
<asp:GridView ID="gdv_kml" runat="server" HorizontalAlign="Center" CellPadding="4"
ForeColor="#333333" GridLines="None">
<RowStyle BackColor="#E3EAEB" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:ButtonField CommandName="Download" Text="Download" />
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<EmptyDataTemplate>
<b>Nenhum KML incluso.</b>
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
谢谢你