2010-02-25 128 views
0

考慮一個包含兩列的gridview行......每列都有兩個文本框...第一個文本框中的Onkeypress我必須更新第二個文本框中的值... ..是否有可能與jQuery ....Jquery +從gridview中的另一個文本框更新一個文本框

編輯: Grid http://img85.imageshack.us/img85/4044/gridp.jpg

我想告訴Closing Advance based on Advance Detucted textbox keypress

ClosingAdvance=OpeningADvance-AdvanceDetucted ....

<table class="grid-view" id="ctl00_ContentPlaceHolder1_gridEmployee" style="border: 0px none rgb(244, 242, 242); border-collapse: collapse;" border="0" cellspacing="0" rules="all"> 
     <tbody><tr class="gridHeaderimg"> 
      <th scope="col" style="width: 10%;"> 

         Name 
        </th><th scope="col" style="width: 10%;"> 
        Salary Basis 
        </th><th scope="col" style="width: 12%;"> 
         Salary Per Day 
        </th><th scope="col" style="width: 12%;"> 
        No of Days Present 
        </th><th scope="col" style="width: 12%;"> 
        Opening Advance 
        </th><th scope="col" style="width: 12%;"> 
        Advance Detucted 
        </th><th scope="col" style="width: 12%;"> 

        Closing Advance 
        </th><th scope="col" style="width: 10%;"> 
        Salary Given 
        </th> 
     </tr><tr class="normal"> 
      <td class="GridCs" style="width: 10%;" align="left"> 
         <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_LblEmpName">Natarajan</span> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$HiddenId" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_HiddenId" value="16" type="hidden"> 
        </td><td class="GridCs" style="width: 10%;" align="left"> 

        <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_LblSalary">Weekly</span> 
        </td><td class="GridCs" style="width: 12%;" align="left"> 
         <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_LblSalaryPerDay">150.00</span> 

        </td><td style="width: 12%;" align="center"> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtDaysPresent" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_TxtDaysPresent" class="text_box_height_14_width_50" type="text"> 

        </td><td class="GridCs" style="width: 12%;" align="left"> 
         <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_LblOpeningAdv">500.00</span> 

        </td><td style="width: 12%;" align="center"> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtAdvanceDeducted" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtAdvanceDeducted\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_TxtAdvanceDeducted" class="text_box_height_14_width_50" type="text"> 

        </td><td style="width: 12%;" align="center"> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtClosingAdvance" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_TxtClosingAdvance" class="text_box_height_14_width_50" type="text"> 
        </td><td style="width: 10%;" align="center"> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl02$TxtSalary" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl02_TxtSalary" class="text_box_height_14_width_50" type="text"> 

        </td> 
     </tr><tr class="alternate"> 
      <td class="GridCs" style="width: 10%;" align="left"> 

         <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_LblEmpName">Pandian</span> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl03$HiddenId" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_HiddenId" value="17" type="hidden"> 
        </td><td class="GridCs" style="width: 10%;" align="left"> 
        <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_LblSalary">Weekly</span> 
        </td><td class="GridCs" style="width: 12%;" align="left"> 
         <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_LblSalaryPerDay">122.00</span> 

        </td><td style="width: 12%;" align="center"> 

         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl03$TxtDaysPresent" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_TxtDaysPresent" class="text_box_height_14_width_50" type="text"> 

        </td><td class="GridCs" style="width: 12%;" align="left"> 
         <span id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_LblOpeningAdv">0.00</span> 
        </td><td style="width: 12%;" align="center"> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl03$TxtAdvanceDeducted" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$gridEmployee$ctl03$TxtAdvanceDeducted\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_TxtAdvanceDeducted" class="text_box_height_14_width_50" type="text"> 

        </td><td style="width: 12%;" align="center"> 
         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl03$TxtClosingAdvance" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_TxtClosingAdvance" class="text_box_height_14_width_50" type="text"> 
        </td><td style="width: 10%;" align="center"> 

         <input name="ctl00$ContentPlaceHolder1$gridEmployee$ctl03$TxtSalary" id="ctl00_ContentPlaceHolder1_gridEmployee_ctl03_TxtSalary" class="text_box_height_14_width_50" type="text"> 

        </td> 
     </tr> 
    </tbody></table> 
+0

你能更具體,並提供一些標記? – 2010-02-25 07:06:24

+0

@Tom請參閱我的編輯... – 2010-02-25 07:20:38

回答

0

我嘗試使用Javascript和得到的答案,

function totalAmount(e, obj) { 

    var tbl = document.getElementById('ctl00_ContentPlaceHolder1_gridEmployee'); 
    var tblRows = tbl.rows.length; 
    var result = 0; 
    var str1; 
    if (obj != null) { 
     str1 = obj.id; 
    } else { 
     str1 = this.id; 
    } 
    var Splitstr = str1.split('_'); 
    var lastChar = Splitstr[3].substring(3, Splitstr.length); 
    if (str1 == 'ctl00_ContentPlaceHolder1_gridEmployee_ctl' + lastChar + '_TxtAdvanceDeducted') { 
     var str2 = 'ctl00_ContentPlaceHolder1_gridEmployee_ctl' + lastChar + '_txtOpeningAdv'; 
     var str3 = 'ctl00_ContentPlaceHolder1_gridEmployee_ctl' + lastChar + '_TxtClosingAdvance'; 
     var txtDeduct = document.getElementById(str1).value; 
     var txtOpenAdv = document.getElementById(str2).value; 
     var txtCloAdv = document.getElementById(str3).value; 
     var totRes = txtOpenAdv - txtDeduct; 
     document.getElementById(str3).value = totRes.toFixed(2) 
    } 

} 
1

你還沒有提供任何標記,所以我必須做出一些假設。假設1:「預先扣除」的輸入字段有「adv-ded」類。假設2:td包含一個開放預先有一個「adv-open」類。假設3:「關閉進度」輸入有「adv-close」類。

$('input.adv-ded').live('keypress', function(e) { 
    var val; 
    try { 
     val = parseFloat($(this).val()); 
     if (val) { 
      var tr = $(this).closest('tr'); 
      var open = parseFloat(tr.find('td.adv-open').text()); 
      tr.find('input.adv-close').val(open - val); 
     } 
    } catch (e) { 

    } 
}); 

就像這樣。您可能需要爲格式添加一些代碼,但這應該表達一般想法。

+0

@Tom Bartel看看我的編輯 – 2010-02-25 08:24:43

+0

我在談論HTML標記,而不是微軟特定的東西。 – 2010-02-25 09:25:55

+0

好吧我會發布它... – 2010-02-25 09:51:04

相關問題