Click here to Skip to main content
Sign Up to vote bad
good
See more: C#
this is my table structure 2 column rate chart and qty :
ratechart qty
1-5 1
6-10 2
11-20 3
 
i have 3 field on form
1 combobox
1 textbox
1 button
 
i fetch the ratechart column value through combobox , i have that code but
 
my requirement is if user select 1-5 from combobbx , then textbox he cannot enter more than 6 in textbox.
 
same if user select 6-10 from combobox , then he cannot enter more than 12 in textbox
 
while he click on save button he get an error that qty is more..
 
thx in advance genius please helping for the code
Posted 11 Nov '12 - 19:54

Comments
Milind Thakkar - 12 Nov '12 - 2:01
Web or Windows ?
vinayak chavan - 12 Nov '12 - 2:06
windows

1 solution

Hi,
 
You can use range validator. Add range validator dynamically in code behind file in combobox selection change event.
 
In selection change event method Add below code.
 
if(selected range is 1-5)
{
RangeValidator1.ControlToValidate = "TextboxId";
RangeValidator1.MaximumValue = "Give Max what you want";
RangeValidator1.MinimumValue = " Assign min what you want";
}
else if(selected range is 6-12)
{
RangeValidator1.ControlToValidate = "TextboxId";
RangeValidator1.MaximumValue = "Give Max what you want";
RangeValidator1.MinimumValue = " Assign min what you want";
}
Hope this might help you.
  Permalink  
Comments
vinayak chavan - 12 Nov '12 - 2:13
but i have to take data from column to validate?? hot to do this
Mohd. Mukhtar - 12 Nov '12 - 2:21
Same you can check into button click event method and validate accordingly. If you are still not able to solve, Please put some code snippet.
vinayak chavan - 12 Nov '12 - 5:32
where is rangevalidator in windows form
vinayak chavan - 12 Nov '12 - 5:47
i have written code but getting error : input string was not in correct format private void saveButton_Click(object sender, EventArgs e) { // Get value from textBox int number = Int32.Parse(textBox1.Text); // Get value from combobox int selcetedComboValue = Int32.Parse(comboBox1.SelectedItem.ToString()); // Validate Values if (selcetedComboValue <= 5) { if (number <= 6) { // Valid Number } else { // Invalid Number } } else if (selcetedComboValue <= 10) { if (number <= 12) { // Valid Number } else { // Invalid Number } }
Mohd. Mukhtar - 12 Nov '12 - 6:17
here your combobox value is in the form of 1-5 6-10 11-20 so for this you need to add this value into an string. and then split that value in string and then you can convert that value into integer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,123
1 OriginalGriff 6,040
2 CPallini 3,432
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid