Disable gridview link on rows where field is not null?

耗尽温柔 提交于 2019-12-12 19:20:33

问题


I've got an asp gridview where I want to disable the edit hyperlink field on rows where the status field is anything but "New". What logic do I need for this?


回答1:


It's been a while, but I think you need to attach onto the RowDatabound event of the GridView and then access that hyperlink to disable it based on the data used for that row.




回答2:


Add in a template field and simply put in this condition:

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



回答3:


You can use the RowDataBound method of the GridView. Within this, you can then check the value of your status field, and then either hide or disable the Hyperlink.




回答4:


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();
        }

 }


来源:https://stackoverflow.com/questions/6033249/disable-gridview-link-on-rows-where-field-is-not-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!