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:54pm

Comments
Milind Thakkar - 12-Nov-12 2:01am
Web or Windows ?
vinayak chavan - 12-Nov-12 2:06am
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:13am
but i have to take data from column to validate?? hot to do this
Mohd. Mukhtar - 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 - 12-Nov-12 5:32am
where is rangevalidator in windows form
vinayak chavan - 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 - 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
Your Filters
Interested
Ignored
     
0 Christian Graus 577
1 Ron Beyer 341
2 Tadit Dash 243
3 samadhan_kshirsagar 229
4 OriginalGriff 201
0 Sergey Alexandrovich Kryukov 7,061
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,370
4 CPallini 3,034


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