【发布时间】:2017-09-28 19:22:25
【问题描述】:
我想在按下按钮后从后面的代码中获取转发器值。但在我的代码隐藏中,中继器总是出现“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
【问题讨论】:
-
我不确定,但这可能有效:
For each item as (your item type) in itens在此处阅读有关For Each...Next的更多信息:docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/… -
你的意思是变量“itens”是Nothing吗?
-
是的,我的意思是变量是Nothing。
-
我对 vb.net 了解不多,但在 c# 中,您必须将数据绑定到中继器。你在这里做过吗?
-
天哪,这里有很多误解。您是否尝试只使用一个中继器一次编辑所有记录?主啊!
标签: .net vb.net webforms repeater