1

当管理员批准/拒绝任何文档一次然后当管理员再次登录时,他/她将无法再次批准/拒绝文档,并且下拉列表将仅对那些可以批准/拒绝的文档禁用,然后当管理员查看任何新文档时下拉将被启用,当管理员批准/拒绝此文档时,它将禁用下拉列表以再次不批准/拒绝

为此我这样做

protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        //Find the DropDownList in the Row

        DropDownList abc = (e.Row.FindControl("DropDownList9") as DropDownList);
        abc.Enabled = false;
    }
}

但是这段代码告诉我所有的下拉列表都是禁用的。

任何解决方案我将如何做到这一点?

4

3 回答 3

1

您需要从每一行访问数据项,我假设它在您绑定到网格的对象上可用,并确定它们是否已被批准/拒绝。如果是这样,那么你应该运行你的逻辑来禁用:

        protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                var yo = (YOUR-OBJECT)e.Row.DataItem;

                if(yo.Status !== null OR yo.Status != 'Not Reviewed'){
                //Find the DropDownList in the Row
                DropDownList abc = (e.Row.FindControl("DropDownList9") 
                as  DropDownList);
                abc.Enabled = false;

                }

            }

        }
于 2013-10-23T17:20:40.983 回答
1

根据您的评论,我假设您的 DataSource 是 DataTable 或 DataSet。

如果是这样,您想在RowDataBound 事件中将DataItem 强制转换为DataRowView以获取状态列的值。

在此处输入图像描述

<asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:TemplateField HeaderText="Status">
            <ItemTemplate>
                <asp:DropDownList runat="server" ID="DropDownList9">
                    <asp:ListItem Text="Approve" Value="1" />
                    <asp:ListItem Text="Reject" Value="2" />
                    <asp:ListItem Text="Pending" selected="selected" Value="3">
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var table = new DataTable();
        table.Columns.Add("Id", typeof (int));
        table.Columns.Add("Name", typeof (string));
        table.Columns.Add("ApproveID", typeof(string));

        table.Rows.Add(1, "Jon Doe", "1");
        table.Rows.Add(2, "Eric Newton", "2");
        table.Rows.Add(3, "Marry Doe", "3");

        GridView1.DataSource = table;
        GridView1.DataBind();
    }
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        var item = e.Row.DataItem as DataRowView;

        var dropDownList = e.Row.FindControl("DropDownList9") as DropDownList;

        // Get value from ApproveID column, 
        // and check whehter Approve, Reject or others.
        switch (item["ApproveID"].ToString())
        {
            case "1":
            case "2":
                dropDownList.Enabled = false;
                break;
            default:
                dropDownList.Enabled = true;
                break;
        }
    }
}
于 2013-10-23T18:57:36.227 回答
0

您可以使用此代码询问您在哪一行:

if (e.Row.RowIndex == <aRowNumber>)
{
    ...
}
于 2013-10-23T17:07:20.040 回答