【发布时间】:2017-08-23 04:30:52
【问题描述】:
我有一个绑定到数据源的 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”属性。我只想:
- 能够选中/取消选中复选框(我卡在这里)
- 使用外部按钮执行单个更新
- 其他列必须是只读的
【问题讨论】:
-
我想不出一个干净的方法,但知道一个 hacky 解决方法来做到这一点。但首先要问两个问题:您能否依赖列的顺序始终相同,如果此可编辑列首先出现在网格中是否有问题?
-
我可以依赖列的顺序,但可编辑列宁愿位于列的中间。如果您有一个需要将列放在首位的解决方案,请告诉我。
标签: asp.net gridview checkbox edit autogeneratecolumn