2012-07-05 39 views
-1

我有一個ASP頁面中包含4個文本框和一個單選按鈕的窗體視圖。單擊編輯按鈕時,如果textbox1,textbox2,textbox3中存在值,則應顯示單選按鈕1和文本框4(即,如果任何一個文本框(1,2,3)爲空,則不應顯示textbox1和單選按鈕)如何啓用radiobutton1和textbox4如果值存在於文本框1,文本框2,文本框3

+0

? – Sllix 2012-07-05 17:51:35

+2

[你有什麼試過](http://mattgemmell.com/2008/12/08/what-have-you-tried/)? – 2012-07-05 17:58:15

+0

使用Javascript – Learner 2012-07-05 18:04:55

回答

1

如果您在使用jQuery:

$("#idOfEditButton").live('click', function(){ 

    if(!$('#idOfTxt1').val() || !$('#idOfTxt2').val() || !$('#idOfTxt3').val()){ 
     $('#idOfRadio').hide(); 
     $('#idOfTxt4').hide(); 
    } 
    else{ 
     $('#idOfRadio').show(); 
     $('#idOfTxt4').show(); 
    } 
}); 

編輯

您還可以使用類,那麼你的if語句(僅一次)添加$('.classNameOfAllTxt')。 和$('.classfTxt4AndRadio').show(); // or hide

0

在窗體視圖編輯事件,查找控制和檢查,如果文本框包含像

文本框TextBox1中= formView.FindControl(「TextBox1中」)作爲文本框的文本;

同樣發現TextBox2中,TextBox3,TextBox4和Radiobutton1

然後比較

if(textbox1.Text != string.Empty && textBox2.Text != string.Empty && textBox3.Text != string.Empty) 
{ 
    textbox4.Visible = true; 
    Radiobutton1.Visible = true; 
} 
else 
{ 
    // set visibility to false 
} 

做到這一點像在事件下面

protected void FormView1_ModeChanged(object sender, EventArgs e) 
    { 

     if (FormView1.CurrentMode == System.Web.UI.WebControls.FormViewMode.Edit) 
     { 
      **// Find Controls and Check ConditionHere** 
     } 
    } 

試試吧。希望能幫助到你。

對於JavaScript嘗試是這樣的:你使用jQuery

function Check() { 
     var b = document.getElementById("<%= FormView1.FindControl("textBox1").ClientID%>"); 
     var a = document.getElementById("<%= FormView1.FindControl("textBox2").ClientID%>"); 

     if(a.innerText === "" && b.innerText == "") 
     { 
       // find the control like above and set visibility to false 
       var textbox4 = ....; 
       textbox4.visibility = "block"; // attribute for visibility is not verified by me, check to see the correct one if you have problem hidding or showing. 
     } 

     return false; 

    } 
+0

對不起,你可以在ModeChanged事件中試用它?就像FormView1.CurrentMode == System.Web.UI.WebControls.FormViewMode.Edit然後做...... Javascript!是的,這是可能的,但我必須先嚐試 – Dinesh 2012-07-05 18:51:25

+0

對不起,但我測試了我的JavaScript代碼,但不是服務器端代碼,嘗試使用FormViewDiagnostic PreRender事件,如鏈接顯示http://forums.asp.net/post/2560651.aspx – Dinesh 2012-07-06 06:51:45