繁体   English   中英

在网格视图中为特定用户禁用按钮字段

[英]Disable a buttonfield for a particular user in a gridview

这可能会造成一些混乱,但是我会尽力解释并感谢您的帮助。

<asp:GridView ID="GridView1" runat="server" Width="936px" AllowPaging="True" AutoGenerateColumns="False" CellPadding="3" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand" style="text-align: center" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellSpacing="2" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:BoundField DataField="TaskId" HeaderText="TaskId" InsertVisible="False" ReadOnly="True" SortExpression="TaskId" />
        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
        <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" Visible="false" />
        <asp:BoundField DataField="Reward" HeaderText="Reward(Rs)" SortExpression="Reward" />
        <asp:BoundField DataField="TimeAllotted" HeaderText="Time(Min)" SortExpression="TimeAllotted" />
        <asp:BoundField DataField="PosterName" HeaderText="Uploader" SortExpression="PosterName" />
        <asp:ButtonField ButtonType="Button" CommandName="Select" Text="Perform Task" ControlStyle-ForeColor="White"  ControlStyle-Font-Bold="true">
            <ControlStyle BackColor="#CC6600" Font-Bold="True" ForeColor="White"></ControlStyle>
        </asp:ButtonField>
    </Columns>

当我单击特定行的按钮字段时,我被定向到一个新页面,该页面要求我执行某些任务。 每当执行任务时,我想为该特定用户禁用“执行任务”按钮字段。

我怎样才能做到这一点?

试试这个代码:

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" ...>
    Other settings
</asp:GridView>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        var button = (Button) e.Row.Cells[e.Row.Cells.Count - 1].Controls[0];
        button.Enabled = CanCurrentUserViewButton();
    }
}

private bool CanCurrentUserViewButton()
{
    //Logic...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM