2017-09-28 71 views
0

我想在按下按鈕後從代碼背後獲得中繼器值。但在我的代碼背後,轉發器總是「0」。我的意思是沒有。從後面的代碼獲取Repeater值

我是我的中繼器在aspx頁面:

<asp:Repeater ID="MyRepeater" runat="server" DataSourceID="SqlDataSourceU"> 
    <HeaderTemplate> 
     <table> 
      <tr> 
       <th>Car Type</th> 
       <th>Cars</th> 
      </tr> 
    </HeaderTemplate> 

    <ItemTemplate> 
     <tr> 
      <td> 
       <asp:Label runat="server" ID="lblUnitTypeValue" Text='<%# Eval("CarTypeName") %>' /> 
      </td> 
      <td> 
       <th> 
        <asp:DropDownList ID="ddlCars" 
         runat="server" 
         DataSourceID="SqlDataSourceViews" 
         DataTextField="problemLocationName" 
         DataValueField="problemLocationId" 
         Width="212px"> 
        </asp:DropDownList> 
        <asp:SqlDataSource ID="SqlDataSourceViews" 
         runat="server" 
         ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
         SelectCommand="SELECT [problemLocationId],[problemLocationName] FROM [ProblemLocation]"></asp:SqlDataSource> 
       </th> 
      </td> 
     </tr> 
    </ItemTemplate> 
    <FooterTemplate> 
     </table> 
    </FooterTemplate> 
</asp:Repeater> 

<asp:SqlDataSource 
     ConnectionString="<%$ ConnectionStrings:QfsAdminConnectionString %>" 
     ID="SqlDataSourceU" runat="server" 
     SelectCommand="SELECT [CarTypeName] FROM [CarType]"> 
</asp:SqlDataSource> 

這是我的代碼隱藏。它不會在我的foreach循環中輸入,因爲始終沒有任何東西。但事實並非如此,我的轉發器有價值。 所以我想要按下按鈕並從我的中繼器獲取值。

Protected Sub btnSaveDefaultView_Click(sender As Object, e As EventArgs) Handles btnSaveDefaultView.Click 
    Dim itens As Repeater = CType(ViewDefaultView.FindControl("RepeaterUnitTypes"), Repeater) 

    For Each item In itens.Items 

    Next 
End Sub 
+0

我不知道,但是這可能工作:'對於每個項目爲(您的項目型)itens'瞭解更多關於'對於每個... Next'這裏:https://開頭的文檔。 microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-each-next-statement – Subaz

+0

你的意思是變量「itens」是什麼? –

+0

是的,我的意思是變量是Nothing。 –

回答

0

使用此代碼從中繼器獲取值,也沒有必要找一箇中繼器:

For Each rItem As RepeaterItem In MyRepeater.Items 
    Dim lbl As Label = DirectCast(rItem.FindControl("lblUnitTypeValue"), Label) 
    If Not IsNothing(lbl) Then 
    Dim value As Integer = Convert.ToInt32(lbl.Text) 
    End If 
Next 
0

去騎馬Awnser這裏!

將由Repeater生成的html解析爲JSON'[CarType]'對象並將其ajax解析爲服務器。

VOALÁ

相關問題