2014-03-01 61 views
1

我有2個表..在我的第一個表中我有一個文本框(txt1)與日期選擇器。 在我的第二個表中,我有5個與日期選擇器類似的文本框(txt2,txt3,txt4,txt5,txt6)。在文本框中輸入的日期必須反映在其他文本框

我的標準是。

最初所有的文本框必須顯示今天的日期,而我改變了我的第一張表中的日期,我的第二張表中的所有文本框必須更改爲我在第一張表中選擇的日期。 我需要一個VB代碼或一個jave腳本來做到這一點。

我已經做了顯示今天的日期,但不能爲另一種情況編碼。

If txt1.Text = "" Then 
       txt1.Text = Format((Date.Today), "dd-MMM-yyyy") 
       If txt1.Text <> "" Then 
        txt2.Text = txt1.Text 
        txt3.Text = txt1.Text 
        txt4.Text = txt1.Text 
        txt5.Text = txt1.Text 
        txt6.Text = txt1.Text 
       End If 
      End If 
+1

您使用asp.net控件或jQuery的日期時間選擇器? – Ajay

+0

@ajay:我使用的是asp.net控件。 – Shuttler

+0

@Shuttler檢查其他新的答案....它是工作...... –

回答

0

添加該頁面加載

protected void Page_Load(object sender, EventArgs e) 
    { 

     if (!IsPostBack) 
     { 
      txt1.Text = DateTime.Now.ToString(); 
     } 
    } 

here you can get today date then after get this date on all textbox 


protected void txt1_TextChanged(object sender, EventArgs e) 
    { 
       If txt1.Text = "" Then 

        If txt1.Text <> "" Then 
         txt2.Text = txt1.Text 
         txt3.Text = txt1.Text 
         txt4.Text = txt1.Text 
         txt5.Text = txt1.Text 
         txt6.Text = txt1.Text 
        End If 
       End If 

} 

u能在txt1_TextChanged事件TextBox1中的添加條件時,文本改變了這一事件火災和你約會中的所有文本,因爲你需要。

<asp:TextBox ID="txt1" AutoPostBack="true" runat="server" Width="83px" ontextchanged="txt1_TextChanged" ></asp:TextBox> 
+0

感謝您的答覆。正如我上面提到的,我已經完成了製作今天的日期。我需要知道,當我在txt1中更改日期時,它必須反映在所有其他文本框中。希望我明白我的意思想。 – Shuttler

+0

是的,你可以得到這個事件的更改日期'txt1_TextChanged'的日期 –

+0

你可以在textbox1的'txt1_TextChanged'事件上添加你的條件,當文本框改變這個事件時,你可以根據需要在所有文本框中獲取日期。 –

0
protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      TextBox1.Text = DateTime.Now.ToString(); 
      TextBox1_TextChanged(TextBox1.Text, null); 
     } 
     else 
     { 
      TextBox1_TextChanged(TextBox1.Text, null); 
     } 
    } 
    protected void TextBox1_TextChanged(object sender, EventArgs e) 
    { 
     TextBox2.Text = TextBox1.Text; 
    } 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>Untitled Page</title> 
</head> 
<body> 

    <form id="form1" runat="server"> 
    <div> 
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" 
     EnablePartialRendering="true"> 
    </asp:ScriptManager> 
     <asp:TextBox ID="TextBox1" AutoPostBack="true" runat="server" 
      ontextchanged="TextBox1_TextChanged"></asp:TextBox> 
     <cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1" 
      Mask="99/99/9999" MaskType="Date" /> 
     <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1" 
      Format="dd/MM/yyyy"> 
     </cc1:CalendarExtender> 
     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> 
     <cc1:MaskedEditExtender ID="MaskedEditExtender2" runat="server" TargetControlID="TextBox2" 
      Mask="99/99/9999" MaskType="Date" /> 
     <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="TextBox2" 
      Format="dd/MM/yyyy"> 
     </cc1:CalendarExtender> 
    </div> 
    </form> 
</body> 
</html> 

添加此代碼是工作

+0

@Shuttler明白了嗎? –

0

我得到使用jQuery。嘗試此您所需的解決方案。

在你的腦袋元素添加下面的代碼的HTML

<head runat="server"> 

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 


    <script> 
     $(function() { 
      $("#txt1").datepicker(); 
      $("#txt2").datepicker(); 
      $("#txt3").datepicker(); 
      $("#txt4").datepicker(); 
      $("#txt5").datepicker(); 
      $("#txt6").datepicker(); 
     }); 
     $(document).ready(function() { 
      ShowTime(); 
      $("#txt1").change(function() { 
       $("#txt2").val($("#txt1").val()); 
       $("#txt3").val($("#txt1").val()); 
       $("#txt4").val($("#txt1").val()); 
       $("#txt5").val($("#txt1").val()); 
       $("#txt6").val($("#txt1").val()); 
      }); 
     }); 
     function ShowTime() { 
      var dt = new Date(); 
      $("#txt1").val($.datepicker.formatDate('mm/dd/yy', new Date())); 
      $("#txt2").val($.datepicker.formatDate('mm/dd/yy', new Date())); 
      $("#txt3").val($.datepicker.formatDate('mm/dd/yy', new Date())); 
      $("#txt4").val($.datepicker.formatDate('mm/dd/yy', new Date())); 
      $("#txt5").val($.datepicker.formatDate('mm/dd/yy', new Date())); 
      $("#txt6").val($.datepicker.formatDate('mm/dd/yy', new Date())); 

     } 

</script> 
</head> 

注: 下面我帶日期的格式,如「MM/DD/YY」,如果你需要的任何其他格式,你需要改變你我碼。

相關問題