[英]Gridview, Autogenerated Column, Checkbox Column Editable
我有一个绑定到数据源的gridview。
<asp:GridView ID="DocumentReviewGrid" runat="server" AllowPaging="True" AllowSorting="True"
EnableModelValidation="True" Width="100%" BorderStyle="None"
CssClass="docnav_data" BorderWidth="1px" GridLines="None" DataSourceID="DocumentReviewDataSource"
HorizontalAlign="Left" OnRowDataBound="DocumentReviewGrid_RowDataBound"
OnRowCreated="DocumentReviewGrid_RowCreated" CellSpacing="5"
PageSize="20" OnPageIndexChanged="DocumentReviewGrid_PageIndexChanged">
<AlternatingRowStyle BackColor="#EBF2F9" BorderStyle="None" />
<FooterStyle HorizontalAlign="Left" />
<HeaderStyle BackColor="#E7E7E7" HorizontalAlign="Left" />
<PagerSettings Mode="NumericFirstLast" Position="Top" PageButtonCount="4" />
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
如您所见,“自动生成的列”设置为true,因此必须将其保留为此类。 列之一是SQL位值,因此将其表示为复选框。 我只想编辑复选框列,而不使用“ AutoGenerateEditButton”属性。 我只想:
无论如何,几乎不能直接对自动生成的列进行直接操作,因此没有简单的方法可以做到这一点。 因此,您可以做的是创建一个自定义列,该列将始终排在任何自动生成的列之前(同样,此行为无法更改),然后隐藏自动生成的位列。
这里介绍了如何隐藏列。 本质上,您不能使用Columns集合,因此需要执行以下操作:
protected void DocumentReviewGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[X].Visible = false; // hides the first column
}
X
是要隐藏的列的从0开始的索引。
现在,以该列为开头,只需按所需方式定义它即可,保留AutoGenerateColumns="true"
:
<asp:GridView ID="DocumentReviewGrid"...>
<Columns>
<asp:CheckBoxField HeaderText="Esclusione" DataField="Esclusione" />
</Columns>
</asp:GridView>
诚然,这确实有点hacker,但这将使您几乎可以找到所需的位置-显示和可编辑的bool列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.