2014-02-28 89 views
1

下面是我的RadGrid編輯表單的代碼,它工作正常,但我想隱藏佔位符控制ID="plupload"插入/編輯模式EditFormSettingsRadComboBox1索引更改事件。隱藏RadGrid EditFormSettings控制運行時

任何人都可以請幫忙解決這個問題嗎?

<editformsettings editformtype="Template"> 
    <FormTemplate> 
     <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;">      
      <tr> 
       <td> 
        <table id="Table4" cellspacing="1" cellpadding="1" width="50%" border="0" class="module"> 
         <tr> 
          <td> 
           Name: 
          </td> 
          <td> 
           <asp:TextBox ID="TextBox2" Text='<%# Bind("Name") %>' runat="server" TabIndex="8"> 
           </asp:TextBox> 
          </td> 
         </tr>  
         <asp:PlaceHolder ID="plupload" runat="server" > 
          <tr> 
           <td> 
            File Upload : 
           </td> 
           <td> 
            <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" OnClientFileUploaded="OnClientFileUploaded" MultipleFileSelection="Disabled" AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576" onvalidatingfile="RadAsyncUpload1_ValidatingFile"> 
            </telerik:RadAsyncUpload> 
           </td> 
          </tr> 
         </asp:PlaceHolder> 
        </table> 
       </td> 
       <td> 
       </td> 
      </tr> 
      <tr> 
       <td align="right" colspan="2"> 
        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp; 
        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button> 
       </td> 
      </tr> 
     </table> 
    </FormTemplate> 
</editformsettings> 

這裏是我的radcombobox控件代碼:

<telerik:RadComboBox ID="RadComboBox1" runat="server" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" AutoPostBack="True"> 
    <Items> 
     <telerik:RadComboBoxItem Value="1" Text="Show All" /> 
     <telerik:RadComboBoxItem Value="2" Text="Hide File Upload" /> 
    </Items> 
</telerik:RadComboBox> 
+0

你試過在你的radgrid(即(PlaceHolder)Radgrid.FindControl(「plupload」))中找到控件嗎? – Tami

回答

1

因爲你沒有提到在您RadComboBox是,我假設它是RadGrid控制之外。如果是這種情況,我建議你實施一種自定義方法遞歸搜索你的Placeholder

// search for a specified control in the given root control and all its children 
public static Control FindControlRecursive(Control rootControl, string searchControlID) 
{ 
    if (rootControl.ID == searchControlID) return rootControl; 

    foreach (Control controlToSearch in rootControl.Controls) 
    { 
     Control controlToReturn = FindControlRecursive(controlToSearch, searchControlID); 
     if (controlToReturn != null) return controlToReturn; 
    } 
    return null; 
} 

然後,在你的頁面的代碼隱藏,你可以搜索plupload並設置其屬性Visible

protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)) 
{ 
    RadComboBox RadComboBox1 = (RadComboBox)sender; 

    // Get the placeholder control nested inside the RadGrid 
    Placeholder plupload = (Placeholder)FindControlRecursive(RadGrid1, "plupload"); 

    if (plupload != null) 
    { 
     if (RadComboBox1.SelectedValue == "2") 
      plupload.Visible = false; 
     else plupload.Visible = true; 
    } 
}