2017-08-30 41 views
0

我有一個非內容(沒有主)頁面與中繼器執行我想要的,但是當我將相同的代碼移動到內容頁面(與主)時,findControl在RepeaterItems循環中不再有效。repeater.findcontrol不工作在內容頁面

ASPX:

<ItemTemplate> 
      <div class="row" id="qrow" runat="server" data-id='<%#Eval("callQuestionID") %>' data-type='<%#Eval("callQuestionResponseType") %>' data-parent='<%#Eval("callQuestionParent") %>'> 
       <div class="col-md-4"> 
        <asp:Label ID="questonTextLabel" runat="server" Text='<%# Eval("callQuestionText") %>'></asp:Label> 
       </div> 
       <div class="col-md-4"> 
        <asp:Panel ID="Panel1" runat="server"></asp:Panel> 
       </div> 
      </div> 
     </ItemTemplate> 

的ItemDataBound exerp

Dim newRBY As New RadioButton 
       newRBY.InputAttributes.Add("data-id", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
       newRBY.InputAttributes.Add("data-idy", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
       newRBY.ID = "rby" 
       newRBY.Text = "Yes" 
       newRBY.GroupName = "qid" & CType(e.Item.DataItem, DataRowView)("callQuestionID") 
       CType(e.Item.FindControl("Panel1"), Panel).Controls.Add(newRBY) 
       Dim newRBN As New RadioButton 
       newRBN.InputAttributes.Add("data-id", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
       newRBN.InputAttributes.Add("data-idn", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
       newRBN.ID = "rbn" 
       newRBN.Text = "No" 
       newRBN.GroupName = "qid" & CType(e.Item.DataItem, DataRowView)("callQuestionID") 
       CType(e.Item.FindControl("Panel1"), Panel).Controls.Add(newRBN) 

帖子的用戶交互處理:

For Each questionRow As RepeaterItem In questionRepeater.Items 
    ... 
    Dim rby As RadioButton = CType(questionRow.FindControl("rby"), RadioButton) ****** Fails Here ***** 
       If rby.Checked Then 
        dataAccess.callQuestionAnswerTable_Insert(callIDInteger, CInt(rby.InputAttributes("data-id")), "true") 
       ElseIf CType(questionRow.FindControl("rbn"), RadioButton).Checked Then 
        dataAccess.callQuestionAnswerTable_Insert(callIDInteger, CInt(rby.InputAttributes("data-id")), "false") 
       End If 

試圖找到 'RBY' 失敗時在後的用戶交互處理。生成的HTML唯一的區別在於,在內容頁面中,控件ID獲取MainContent_前綴。

我能做些什麼來解決這個問題?

回答

0

如果代碼位於子頁面上,而Repeater位於Master Page本身,則需要指定Master頁面FindControl並在其中找到Repeater。

Dim rpt As Repeater = CType(Master.FindControl("Repeater1"),Repeater) 

然後

For Each questionRow As RepeaterItem In rpt.Items 

(從C#轉換一個代碼翻譯到VB,所以它可能是一個小關,在C#這是Repeater rpt = Master.FindControl("Repeater1") as Repeater;

+0

兩者都在子頁面中。環境中唯一的區別是有一個主頁面。 –

0

,我發現我的問題。這實際上是我有中繼器的綁定在

If Not IsPostBack Then 

塊,我不應該有明顯的。

相關問題