I have this code that populates a textbox based on a cell in the selected row of a gridview
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
txtComment.Text = row.Cells[14].Text.Trim();
}
It displays
in the txtComment textbox if Cell[14] has no data.
Is there a way to prevent the
from appearing when there is no data in the cell of the selected row?
Edit I tried this and it didn't work
if (row.Cells[14].Text.Trim().Length > 1)
{
txtComment.Text = row.Cells[14].Text.Trim();
}
else
{
txtComment.Text = row.Cells[14].Text = "";
}
===================================================================
This worked
if (row.Cells[14].Text.Trim()!=" ")
{
txtComment.Text = row.Cells[14].Text.Trim();
}
else
{
txtComment.Text = row.Cells[14].Text = "";
}
Use this:
Server.HtmlDecode()
For example:
txtComment.Text = Server.HtmlDecode(row.Cells[14].Text);
It handles not only spaces, but also other conversions like ampersands(&) and etc.
Use NullDisplayText=" "
<asp:BoundField DataField="EmployeeName" HeaderText="Name" NullDisplayText=" "/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With