I've noticed that when i populate textboxes from a selected row in a gridview that if the field is blank it displays " " in the textbox.
Here is the solution I came up with. I check each cell before adding it to the textbox.
I get the feeling that I'm either doing something wrong to have this problem in the first place or that there is a better way to handle this.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//// Get the currently selected row using the SelectedRow property.
GridViewRow row = GridView1.SelectedRow;
// Load data from selected row into textboxes
if (row.Cells[1].Text.Trim() != " ")
{
txtEditCust_ID.Text = row.Cells[1].Text.Trim();
}
}
Still a minor hack, but probably better than dealing with . You can set NullDisplayText=" " on GridView column <asp:BoundField> and then use condition like for example:
if (String.IsNullOrWhiteSpace(e.Row.Cells[1].Text))
{
// do something with e.Row
}
In this case, there is no to begin with.
row.Cells[1].Text.Trim()
is not working for , replace it instead:
row.Cells[1].Text.Replace(" ", "")
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