在代码隐藏中访问RadListBox项

时间:2013-07-31 19:43:39

标签: vb.net telerik postback code-behind radlistbox

我有以下RadListBox:

   <telerik:RadListBox ID="AttachmentsRadListBox"  CheckBoxes ="true" runat="server" />

它位于RadWindow中,因此我通过以下代码填充它,只有当RadWidnow可见时才会调用它:

AttachmentsRadListBox.DataSource = AttachDT
AttachmentsRadListBox.DataTextField = "DocumentPath"
AttachmentsRadListBox.DataValueField = "DocumentID"
AttachmentsRadListBox.DataBind()
For Each item As RadListBoxItem In AttachmentsRadListBox.Items
     item.Checked = True
Next

到目前为止,RadListBox已经填充并且所有项目都已经过检查。

现在,在关闭窗口之前按下RadWindow上有一个Save按钮我试图读取AttachmentsRadListBox中的已检查项目(因为用户可能已经更改了已检查项目的状态)。但是,阅读项目的所有努力都失败了,例如在“保存”按钮上单击“我有以下内容”:

Dim test As Integer = AttachmentsRadListBox.Items.Count  // THIS IS ZERO
For Each item As RadListBoxItem In AttachmentsRadListBox.Items  // THERE ARE NO ITEMS
   If Not item.Checked Then
        Dim DocumentIDToDelete As Integer = item.Value
   End If
Next

为什么最后一段代码不像我希望的那样? AttachmentsRadListBox没有通过回发再次受限。唯一有限的时间是RadWindow出现的时候。然后RadWindow上的Save按钮显然会创建一个回发,但我不明白为什么AttachmentsRadListBox在那时不包含任何项目。

1 个答案:

答案 0 :(得分:1)

由于您动态创建AttachmentsRadListBox,您是否会在后续回发中重新创建它?它最终是一个服务器控件,所以你需要确保它被重新创建,因为否则ASP会在后续回发时销毁它。 要了解如何访问RadWindow的ContentTemplate中的控件,您还可以查看以下文章:http://www.telerik.com/help/aspnet-ajax/window-controls-container.html