C# 在RowDataBound事件中启用或禁用超链接

C# 在RowDataBound事件中启用或禁用超链接,c#,asp.net,C#,Asp.net,我的代码有问题。我需要根据从数据库提取的值在ASP.NET GridView中的RowDataBound事件中启用或禁用超链接 如果我的数据库的字段File的值不是null,则超链接将不可见,否则将不可见。在GridView中,我没有计划显示字段File的值 我尝试使用这些解决方案但没有成功,因为我有这个错误 编译器错误消息:CS1502:与“string.IsNullOrEmpty(string)”匹配的最佳重载方法具有一些无效参数 这是我的密码: protected void GridVie

我的代码有问题。我需要根据从数据库提取的值在ASP.NET GridView中的
RowDataBound
事件中启用或禁用超链接

如果我的数据库的字段
File
的值不是
null
,则超链接将不可见,否则将不可见。在GridView中,我没有计划显示字段
File
的值

我尝试使用这些解决方案但没有成功,因为我有这个错误

编译器错误消息:CS1502:与“string.IsNullOrEmpty(string)”匹配的最佳重载方法具有一些无效参数

这是我的密码:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink Srl = (HyperLink)e.Row.FindControl("Srl");     

        foreach (string color in colorList)
        {
            if (!string.IsNullOrEmpty(DataBinder.Eval(e.Row.DataItem, "File")))
            {
                Srl.Visible = true;
            }
        }
    }
}

DataBinder.Eval
返回一个对象。您需要将其转换为
字符串

试试这个:

if (!string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "File"))))
{
    Srl.Visible = true;
}

使用
asp:HiddenField
作为文件值,并使用此行内数据绑定事件

void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink Srl = (HyperLink)e.Row.FindControl("Srl");     

        foreach (string color in colorList)
        {
            string str = (string)DataBinder.Eval(e.Row.DataItem, "File");

            //then you can check
            if (!String.IsNullorEmpty(str ))
            {
                Srl.Visible = true;
            }
        }
    }
 }
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink Srl = (HyperLink)e.Row.FindControl("Srl");     

        foreach (string color in colorList)
        {
            string str = (string)DataBinder.Eval(e.Row.DataItem, "File");

            //then you can check
            if (!String.IsNullorEmpty(str ))
            {
                Srl.Visible = true;
            }
        }
    }
 }