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

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

概述我有这个代码,它基于gridview的选定行中的单元格填充文本框 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { txtComment.Text = row.Cells[14].Text.Trim(); } 它显示& nbsp;如果Cell [14]没有数据, 我有这个代码,它基于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(" ","");

我希望它可以帮助你:)

总结

以上是内存溢出为你收集整理的c# – 防止将空的Gridview数据填充到文本框中“ ”全部内容,希望文章能够帮你解决c# – 防止将空的Gridview数据填充到文本框中“ ”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1240828.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存