【发布时间】:2010-09-17 18:16:00
【问题描述】:
我有这段代码,它根据网格视图的选定行中的单元格填充文本框
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 = "";
}
【问题讨论】:
-
你试过
row.Cells[14].Text = string.Empty;或= "";吗? -
我都试过了 =string.Empty;和="";我仍然得到