gpt4 book ai didi

c# - 防止空 Gridview 数据将 " "填充到文本框中

转载 作者:太空狗 更新时间:2023-10-29 20:44:54 26 4
gpt4 key购买 nike

我有这段代码可以根据 gridview 的选定行中的单元格填充文本框

 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

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

}

如果 Cell[14] 没有数据,它会在 txtComment 文本框中显示  

有没有办法在选中行的单元格中没有数据时,不显示 


编辑我试过了,没用

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 数据将 " "填充到文本框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3737867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com