0

When I write if condition in one line for the textbox i.e.

if (txtNotes.Text.Equals(" ") ? string.Empty: gvrow.Cells[6].Text)

I am getting the error stating:

Cannot implicitly convert type "string" to "bool"

Just want to check where I am going wrong.

1 Answer 1

2

You're confusing the standard if statement syntax with the ternary operator ?:. It's either:

txtNotes.Text = txtNotes.Text.Equals(" ") ? string.Empty : gvrow.Cells[6].Text;

or

if (txtNotes.Text.Equals(" "))
{
    txtNotes.Text = string.Empty;
}
else
{
    txtNotes.Text = gvrow[6].Cells.Text;
}

Edit: from your comment you've stated your setting the value of txtNotes.Text, so I recommend using the ternary operator to achieve this.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks robyaw. actually I am pulling the data from the database, and populating the textbox (txtnotes). If the data equals   then txtNotes.text should be empty otherwise it will pull the data from the gridviewrow (gvrow.Cells[6].Text)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.