Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:54pm
Comments
Milind Thakkar at 12-Nov-12 2:01am
   
Web or Windows ?
vinayak chavan at 12-Nov-12 2:06am
   
windows

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v4
Comments
vinayak chavan at 12-Nov-12 2:13am
   
but i have to take data from column to validate?? hot to do this
Mohd. Mukhtar at 12-Nov-12 2:21am
   
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 at 12-Nov-12 5:32am
   
where is rangevalidator in windows form
vinayak chavan at 12-Nov-12 5:47am
   
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 at 12-Nov-12 6:17am
   
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
0 Sergey Alexandrovich Kryukov 535
1 CPallini 450
2 OriginalGriff 270
3 George Jonsson 256
4 Suvabrata Roy 229
0 OriginalGriff 4,873
1 CPallini 3,900
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,646
4 Gihan Liyanage 2,236


Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100