2016-03-25 7 views
-2

私は複数のtextboxesdropdownのメニューを持っています。2つのテキストボックスの値を追加し、3つのテキストボックスと等しいかどうかをチェックする方法は?

textboxesの合計が3番目のテキストボックスに等しいかどうかを計算してチェックしたいのですが、それに沿ってdropdownメニューがあり、そのドロップダウンメニューの値は+1または-1です。例えば、私は次のように制御しています

txt1 with ddl1; txt2 with ddl2; txt3 with ddl3; txt4 with ddl4; 

は、私がいるかどうか確認したい:

txt1 * ddl1 = ((txt2 * ddl2) + (txt3 * ddl3) + (txt4 * ddl4)) 

また、私は、カスタムバリデータを使用して、その中にこの状態を確認したいのです。あなたが書くことができ、カスタムバリデータのサーバ機能で

答えて

0

あなたはまずtextboxとddlの値を整数に変更する必要があります。

int txt1 = Convert.ToInt32(TextBox1.Text); int dd1 = Convert.ToInt32(DropDownList1.SelectedValue);

 int txt2 = Convert.ToInt32(TextBox2.Text); 
     int dd2 = Convert.ToInt32(DropDownList2.SelectedValue); 

     int txt3 = Convert.ToInt32(TextBox3.Text); 
     int dd3 = Convert.ToInt32(DropDownList3.SelectedValue); 


     if (txt1 * dd1 == (txt2 * dd2) + (txt3 * dd3)) 
     { 
      //YOur code here 
     } 
+0

ありがとう@Boopathy。 – SBelim

0
function Total() { 
      var sumofall;    
      var FirstText = document.getElementById('txt1').value; 
      var SecondText = document.getElementById('txt2').value; 
      var ThirdText = document.getElementById('txt3').value; 
      var FouthText = document.getElementById('txt4').value; 
      var dropdown = document.getElementById("ddl1"); 
      var dropdown2 = document.getElementById("ddl2"); 
      var dropdown3 = document.getElementById("ddl3"); 
      var dropdown4 = document.getElementById("ddl4"); 
      var value = dropdown.options[dropdown.selectedIndex].value; 
      var value2 = dropdown2.options[dropdown2.selectedIndex].value; 
      var value3 = dropdown3.options[dropdown3.selectedIndex].value; 
      var value4 = dropdown4.options[dropdown4.selectedIndex].value; 
      var text = dropdown.options[dropdown.selectedIndex].text; 
      var text2 = dropdown2.options[dropdown2.selectedIndex].text; 
      var text3 = dropdown3.options[dropdown3.selectedIndex].text; 
      var text4 = dropdown4.options[dropdown4.selectedIndex].text; 

      if (FirstText == "") 
       FirstText = 0; 
      if (dropdown == "") 
       dropdown = 0; 

      var result = parseInt(FirstText) * parseInt(text); 
      if (!isNaN(result)) { 

      } 
      if (SecondText == "") 
       SecondText = 0; 
      if (dropdown2 == "") 
       dropdown2 = 0; 

      if (ThirdText == "") 
       ThirdText = 0; 
      if (dropdown3 == "") 
       dropdown3 = 0; 

      if (FouthText == "") 
       FouthText = 0; 
      if (dropdown4 == "") 
       dropdown4 = 0; 

      var result2 = parseInt(SecondText) * parseInt(text2); 
      var result3 = parseInt(ThirdText) * parseInt(text3); 
      var result4 = parseInt(FouthText) * parseInt(text4); 

      if (!isNaN(result2) && !isNaN(result3) && !isNaN(result4)) { 
       sumofall = result2 + result3 + result4; 
      } 


      if (result == sumofall) 
       alert('Something'); 
      else 
       alert('Error..Not Matched'); 
       return false; 
    } 
0

int firstValue = 0; 
if(int32.TryParse(txt1.Text), out firstValue) 
{ 
    int secondValue = 0; 
    if(int32.TryParse(txt2.Text), out secondValue) 
    { 
     // ... 
     // check other value, then 
     arg.IsValid = firstValue * Convert.ToInt32(ddl1.SelectedValue) == 
        (secondValue * Convert.ToInt32(ddl2.SelectedValue)) + 
        (thirdValue * Convert.ToInt32(ddl3.SelectedValue)) + 
        (fourthValue * Convert.ToInt32(ddl4.SelectedValue)); 

    } 
    else 
     lblEsito = "Il valore nel secondo TextBox non è un intero"; 
} 
else 
    lblEsito = "Il valore nel primo TextBox non è un intero"; 

私はdropdownlistsの値を仮定している整数であり、任意の値を「0」を「選択」または「」に存在していますドロップダウンリストが制御します。 次回はコードを投稿する必要があります。

関連する問題