如何在C#中禁用数据网格视图中的链接 [英] How to disable link in datagrid view in C#

查看:66
本文介绍了如何在C#中禁用数据网格视图中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have textbox and a datagrid view that contains three links I want to disable the links at the beginning after when I filled out for example the textbox1 the first link will activate how to do please and thanks in advance





我尝试过:





What I have tried:

if (textBox4.Text == "0" && textBox4.Text == "0" && textBox4.Text == "0")
            {
                dataGridView2.Rows.Cell[1].Enable = true;
            }

推荐答案

如果您希望在文本框值为0时禁用链接代码应该有帮助。您可以根据需要更新代码。



If you are looking to have your link disabled while your textbox value is "0" below code should help. You can update the code per your need.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        TextBox textControl = e.Row.FindControl("textbox4") as TextBox;
        LinkButton linkControl = e.Row.FindControl("link1") as LinkButton;

        if(textControl.Text.Equals("0"))
        {
            linkControl.Enabled = false;
        }
        else
        {
            linkControl.Enabled = true;
        }
    }
}


这篇关于如何在C#中禁用数据网格视图中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆