Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
MT_ 12-Nov-12 2:01am    
Web or Windows ?
Master Vinu 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.

C#
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.
 
Share this answer
 
v4
Comments
Master Vinu 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.
Master Vinu 12-Nov-12 5:32am    
where is rangevalidator in windows form
Master Vinu 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900