Sapna
Sapna

Reputation: 53

I Can not disable button due to error Cannot implicitly convert type string to bool

I need to disable search button after some information is displayed in the grid view. when i wrote "btnSearch.Enabled="false";" in the grid view button, Cannot implicitly convert type 'string' to 'bool' message will raise may give me solution please ?

protected void gvEmployeeLeaves_SelectedIndexChanged(object sender, EventArgs e)
  {
        btnSearch.Enabled="false";
  }

Upvotes: 0

Views: 241

Answers (4)

user3462653
user3462653

Reputation:

protected void gvEmployeeLeaves_SelectedIndexChanged(object sender, EventArgs e)
  {
        btnSearch.Enabled=false; /*btnSearch.Enabled="false"; is wrong
  }

Upvotes: 0

Nayeem Mansoori
Nayeem Mansoori

Reputation: 831

 protected void gvEmployeeLeaves_SelectedIndexChanged(object sender, EventArgs e)
  {
        btnSearch.Enabled=Convert.ToBoolean("false");
  }

Upvotes: 0

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

Problem : "false" is not a valid boolean value(it is a string)

so you should change either string "false" to false or convert string "false" to boolean.

You can directly assign the false to the Enabled property without double quotes as below:

btnSearch.Enabled = false;

OR

You can convert the string false to boolean value using Convert.ToBoolean() method and then assign

Try This:

btnSearch.Enabled=Convert.ToBoolean("false");

Upvotes: 1

Hassan
Hassan

Reputation: 5430

You are providing string instead of boolean value. Just remove the double quotes:

btnSearch.Enabled = false;

Upvotes: 0

Related Questions