2012-07-25 15 views
0

我有一箇中繼器,每個項目都有一個複選框和單選按鈕。中繼器與回發

  • 複選框選中時(帶自動回傳)禁止所有的物品內部的控制
  • 的單選按鈕,顯示檢查一次(也有自動回傳)一個彈出。

情況是:如果在中繼器的任何項目中都有一個單選按鈕被選中,當我選中複選框控件以禁用項目時,彈出窗口將顯示。在回發期間,選中的單選按鈕將導致彈出窗口顯示。

我該如何預防?複選框應該只禁用不顯示彈出窗口的項目。

我的代碼

protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    protected void rptr1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
    { 


      if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) 
      { 
       Label lbl1 = (Label)e.Item.FindControl("lbl_dg_task"); 
       Label lbl2 = (Label)e.Item.FindControl("lbl_dg_seq"); 
       CheckBox chb = (CheckBox)e.Item.FindControl("chkb_NO"); 
       RadioButton l1 = (RadioButton)e.Item.FindControl("L1"); 
       RadioButton l2 = (RadioButton)e.Item.FindControl("L2"); 
       RadioButton l3 = (RadioButton)e.Item.FindControl("L3"); 
       RadioButton l4 = (RadioButton)e.Item.FindControl("L4"); 
       RadioButton r1 = (RadioButton)e.Item.FindControl("R1"); 
       RadioButton r2 = (RadioButton)e.Item.FindControl("R2"); 
       RadioButton r3 = (RadioButton)e.Item.FindControl("R3"); 
       RadioButton r4 = (RadioButton)e.Item.FindControl("R4"); 
       AjaxControlToolkit.ModalPopupExtender mpex = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("mpe1"); 

       if (l1.Checked) 
       { 
        //pop.Enabled = true; 
        ModalPopupExtender1.Show(); 
       } 


       if (chb.Checked == true) 
       { 

        l1.Enabled = false; 
        l2.Enabled = false; 
        l3.Enabled = false; 
        l4.Enabled = false; 
        r1.Enabled = false; 
        r2.Enabled = false; 
        r3.Enabled = false; 
        r4.Enabled = false; 
        lbl1.CssClass = "grayedout"; 
        lbl2.CssClass = "grayedout"; 


       } 
       else 
       { 
        l1.Enabled = true; 
        l2.Enabled = true; 
        l3.Enabled = true; 
        l4.Enabled = true; 
        r1.Enabled = true; 
        r2.Enabled = true; 
        r3.Enabled = true; 
        r4.Enabled = true; 
        lbl1.CssClass = "seq"; 
        lbl2.CssClass = "task"; 


       } 
      } 


     } 


    protected void rptr1_PreRender(object sender, EventArgs e) 
    { 

      foreach (RepeaterItem item in rptr1.Items) 
      { 
       if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item) 
       { 
        CheckBox chb = (CheckBox)item.FindControl("chkb_NO"); 
        Label lbl1 = (Label)item.FindControl("lbl_dg_task"); 
        Label lbl2 = (Label)item.FindControl("lbl_dg_seq"); 
        RadioButton l1 = (RadioButton)item.FindControl("L1"); 
        RadioButton l2 = (RadioButton)item.FindControl("L2"); 
        RadioButton l3 = (RadioButton)item.FindControl("L3"); 
        RadioButton l4 = (RadioButton)item.FindControl("L4"); 
        RadioButton r1 = (RadioButton)item.FindControl("R1"); 
        RadioButton r2 = (RadioButton)item.FindControl("R2"); 
        RadioButton r3 = (RadioButton)item.FindControl("R3"); 
        RadioButton r4 = (RadioButton)item.FindControl("R4"); 
        AjaxControlToolkit.ModalPopupExtender mpex = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1"); 


        if (chb.Checked == true) 
        { 
         l1.Enabled = false; 
         l2.Enabled = false; 
         l3.Enabled = false; 
         l4.Enabled = false; 
         r1.Enabled = false; 
         r2.Enabled = false; 
         r3.Enabled = false; 
         r4.Enabled = false; 
         l1.Checked = false; 
         lbl1.CssClass = "grayedout"; 
         lbl2.CssClass = "grayedout"; 

        } 
        else 
        { 
         l1.Enabled = true; 
         l2.Enabled = true; 
         l3.Enabled = true; 
         l4.Enabled = true; 
         r1.Enabled = true; 
         r2.Enabled = true; 
         r3.Enabled = true; 
         r4.Enabled = true; 
         lbl1.CssClass = "seq"; 
         lbl2.CssClass = "task"; 


        } 

        if (l1.Checked) 
        { 

         //pop.Enabled = true; 
         ModalPopupExtender1.Show(); 


        } 

       } 
      } 
     } 
+0

您應該考慮按照預期使用事件。 ItemDataBound在顯示之前處理數據,PreRender在事件處理程序之後操作任何對象,並使用事件處理程序處理事件。您應該考慮使用中繼器ItemCommand來確定適當的顯示邏輯。 – 2012-07-25 12:12:39

回答

1

不要使用PreRender事件,以決定是否顯示彈出,但使用單選按鈕的OnCheckedChanged事件來證明這一點。

l1.CheckedChanged = (sender, e) => { if (l1.Checked) ModalPopupExtender1.Show(); }; 
+0

非常感謝,解決了這個問題,但我必須先爲無線電創建事件處理程序並將其插入到Page_Load事件中。 – 2012-07-29 09:32:46

+0

現在又出現了另一個問題,我爲l1創建了另一個彈出窗口,它工作正常。 – 2012-07-29 09:35:36

+0

如何「正常工作」是一個問題? – 2012-07-29 09:37:51