?
Solved

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

Posted on 2012-08-29
4
Medium Priority
?
1,161 Views
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
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
0
Comment
Question by:newjeep19
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38345946
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
 

Author Comment

by:newjeep19
ID: 38346127
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
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 2000 total points
ID: 38346180
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
 

Author Closing Comment

by:newjeep19
ID: 38346204
Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 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