Auto check an ASP.net check box when the value of an asp.net textbox is > or = to $5000 in an asp.net gridview

I am looking for how to automatically check a checkbox in an ASP.NET gridview row when the value in a textbox in that same row is  = too or greater than $5000.00
EX.
if (txtTextbox >= 5000)
{
   chkCheckbox.Checked = true;
}
   else
{
  chkCheckbox.Checked = false;
}

I have searched all over the internet and have not come across any examples
Thanks
newjeep19Asked:
Who is Participating?
 
Rajar AhmedConsultantCommented:
try this,
//if (!string.IsNullOrEmpty(txtBox.Text) && Int32.Parse(txtBox.Text) >= 500)
  if (IsNumeric(TextBox1.Text) && Int32.Parse(TextBox1.Text) >= 500)//Replace To this
....................
..
//Add this method
 public static Boolean IsNumeric(string stringToTest)
    {
        int result;
        return int.TryParse(stringToTest, out result);
    }

Open in new window

0
 
Rajar AhmedConsultantCommented:
Add row databound to your gridview and try this,
onrowdatabound="gvData_RowDataBound"
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox txtBox = (TextBox)e.Row.FindControl("txtTextbox");//Give your textbox Id 

            CheckBox chkBox = (CheckBox)e.Row.FindControl("chkCheckbox");
            //if (Convert.ToInt32(txtBox.Text) >= 5000)
            if (!string.IsNullOrEmpty(txtBox.Text) && Int32.Parse(txtBox.Text) >= 500)
            {
                chkBox.Checked = true;
            }
            else{
                chkBox.Checked = false;
            }


        }
    }

Open in new window

0
 
newjeep19Author Commented:
I am getting the below error message with this part of the code:
             Int32.Parse(txtBox.Text) >= 500)
error message:
Input string was not in a correct format.
0
 
newjeep19Author Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.