微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 防止将空的Gridview数据填充到文本框中“ ”

我有这个代码,它基于gridview的选定行中的单元格填充文本框
protected void GridView1_SelectedindexChanged(object sender,EventArgs e)
    {

        txtComment.Text = row.Cells[14].Text.Trim();

    }

显示& nbsp;如果Cell [14]没有数据,则在txtComment文本框中.

有没有办法防止& nbsp;当所选行的单元格中没有数据时出现?

编辑
我尝试过这个并没有用

if (row.Cells[14].Text.Trim().Length > 1)
{
    txtComment.Text = row.Cells[14].Text.Trim();
}
else
{
    txtComment.Text = row.Cells[14].Text = "";
}

================================================== =================

这很有效

if (row.Cells[14].Text.Trim()!=" ")
{
    txtComment.Text = row.Cells[14].Text.Trim();
}
else
{
    txtComment.Text = row.Cells[14].Text = "";
}

解决方法

我也有像这样的问题,我发现这也很有用:
txtComment.Text = row.Cells[14].Text.Replace(" ","");

我希望它可以帮助你:)

原文地址:https://www.jb51.cc/csharp/98183.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐