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

Posted on 2012-08-29
Last Modified: 2012-08-29
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
if (txtTextbox >= 5000)
   chkCheckbox.Checked = true;
  chkCheckbox.Checked = false;

I have searched all over the internet and have not come across any examples
Question by:newjeep19
    LVL 18

    Expert Comment

    by:Rajar Ahmed
    Add row databound to your gridview and try this,
    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;
                    chkBox.Checked = false;

    Open in new window


    Author Comment

    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.
    LVL 18

    Accepted Solution

    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


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now