我想在gridview 中隐藏一列。我使用以下代码;
dgvTekleme.Columns[1].Visible = false;
但这不起作用。(可能因为在代码中使用该列而不起作用)有没有解决方案可以在代码隐藏中隐藏列
您可以手动执行此操作..... goto asp:gridview 标记并在 gridview 标记中设置 autogeneratecolumn="false" 如果您不想显示某些列,请不要写该列....例如,如果您不想显示 prodId 列,只需擦除该行....并手动编写以显示数据,例如!!!!!!!!!!!!
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="ProdID" DataField="prodid" ReadOnly="true" />
<asp:BoundField HeaderText="ProdName" DataField="ProdName" />
<asp:BoundField HeaderText="Quantity" DataField="quantity" />
<asp:BoundField HeaderText="SupplierID" DataField="SupplierId" />
<asp:BoundField HeaderText="StockLvl" DataField="stocklevel" />
<asp:BoundField HeaderText="MinStockLvl" DataField="minstocklevel" />
<asp:BoundField HeaderText="CostPrice" DataField="costprice" />
<asp:BoundField HeaderText="SalesPrice" DataField="saleprice" />
<asp:BoundField HeaderText="Loc" DataField="location" />
<asp:BoundField HeaderText="ProdCode" DataField="prodtypecode" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
或者您可以查看此链接: How to hide columns in an ASP.NET GridView with auto-generated columns?