我有以下 GridView
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
OnRowCommand="GridView1_RowCommand" DataKeyNames="Chart_Id"
AutoGenerateColumns="False" EnableModelValidation="True" >
<Columns>
<asp:CommandField ShowEditButton="False" ShowDeleteButton="False" ShowInsertButton="False" />
<asp:BoundField DataField="Week" HeaderText="Week" SortExpression="Week" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" ItemStyle-Wrap="False" />
<asp:BoundField DataField="Host" HeaderText="Host" SortExpression="Host" />
<asp:BoundField DataField="Topic_1" HeaderText="Topic 1" SortExpression="Topic_1" />
<asp:BoundField DataField="Topic_2" HeaderText="Topic 2" SortExpression="Topic_2"
HeaderStyle-Wrap="False" />
<asp:BoundField DataField="Topic_3" HeaderText="Topic 3" SortExpression="Topic_3" />
<asp:BoundField DataField="Topic_4" HeaderText="Topic 4" SortExpression="Topic_4" />
</Columns>
</asp:GridView>
默认情况下,我将编辑/插入/取消按钮设置为 false。
然后在后面的代码中,我希望能够在某些条件下将这些设置为 true。
string theUser = Helpers.GetUser();
string admin = "adminName";
if (theUser == admin) {
// Set the buttons to true
}
我一直在寻找方法来做到这一点,有人建议使用 AutoGenerate 属性,然后像这样启用它们:
GridView1.AutoGenerateEditButton = true;
GridView1.AutoGenerateDeleteButton = true;
GridView1.AutoGenerateInsertButton = true; // This one throws an error
唯一的问题是,在主 ASPX 页面或后面的代码中似乎不存在 AutogenerateInsertButton。
谁能建议我访问这些属性并将它们设置为 true 的一些方法?
谢谢你。