下面是我的RadGrid编辑表单的代码,它工作正常,但我希望在ID="plupload"
索引更改事件的EditFormSettings
的插入/编辑模式下隐藏占位符控件RadComboBox1
有人可以帮忙解决这个问题吗?
<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>
<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 :(得分: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;
}
}