我希望在按下按钮后从代码中获取转发器值。但在我的代码隐藏中,转发器总是来了#34; 0"。我的意思是没有。
我是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 :(得分: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
答案 1 :(得分:0)
Go Horse Awnser在这里!
将Repeater生成的html解析为JSON'[CarType]'对象,并将其解析为服务器。
VOALÁ