在字段不为空的行上禁用gridview链接?

时间:2011-05-17 15:29:20

标签: c# asp.net gridview

我有一个asp gridview,我想在行上禁用编辑超链接字段,其中状态字段不是“新建”。我需要什么逻辑?

4 个答案:

答案 0 :(得分:2)

添加template field并简单地置于此条件:

<asp:TemplateField HeaderText="Edit">
   <asp:LinkButton ID="LinkButton1" Text="Edit" runat="server" Enabled='<%# Convert.ToString(Eval("Status")) == "New" ? true : false %>'></asp:LinkButton>
</asp:TemplateField>

答案 1 :(得分:2)

已经有一段时间了,但我认为您需要附加到RowDatabound的{​​{1}}事件,然后根据用于该行的数据访问该超链接以禁用它。

答案 2 :(得分:1)

您可以使用GridView的RowDataBound方法。在此范围内,您可以检查状态字段的值,然后隐藏或禁用超链接。

答案 3 :(得分:0)

I used something once. It is not the best practice but it worked for me.
BTW I used it an Edit Button not in an Edit Text but i think it has to work as the same way.

 In the RowDataBound Event of the GridView use this:

 if (e.Row.RowType == DataControlRowType.DataRow)
 {
        //Use the index of your Edit Cell
        if(bool.Parse(DataBinder.Eval(e.Row.DataItem, "Status"))
        {
            e.Row.Cells[8].Controls.Clear();
        }

 }
相关问题