[英]With a custom control that's inside of an ItemTemplate (Repeater), how can I access values from the repeater item?
[英]Repeater html values always taking last item's value
嗨,我正在使用ASP中繼器用於列表項的特殊文本框,並使用div來提供警報文本框類型(數字或字符串等)。
<asp:Repeater ID="rptProperties" runat="server" DataSourceID="dsProperties" OnItemDataBound="rptProperties_ItemDataBound">
<ItemTemplate>
<li>
<div class="form_title"><%# Eval("ad_en")%> </div>
<div class="form_content" id="fk_<%# Eval("id")%>">
<asp:HiddenField runat="server" ID="hdnPropertyID" Value='<%# Eval("id") %>' />
<asp:TextBox runat="server" ID="txtProperty"></asp:TextBox>
<div class="alert">
<%= labelType %>
</div>
<div class="select_box" runat="server" id="divSelectBox">
<asp:DropDownList runat="server" ID="ddlProperty" CssClass="data_select">
<asp:ListItem>Select</asp:ListItem>
</asp:DropDownList>
</div>
</div>
</li>
</ItemTemplate>
</asp:Repeater>
這是后面的代碼;
if (id!=130)
{
txtProperty.Attributes.Add("Class", "data_input");
labelType = GetLocalResourceObject("stringType").ToString();
}
else
{
labelType = GetLocalResourceObject("intType").ToString();
}
即使是代碼觸發(如果同時觸發),所有轉發器文本框都將采用“ intType”值,這是最后一項的值。 但是;
txtProperty.Attributes.Add("Class", "data_input");
線按我的要求工作正常。 對我來說只有“ labelType”變量問題。 謝謝
對不起,但這行不通。
<%%>代碼塊在c#代碼運行完后編譯運行時。 因此,您更改了labelType,然后運行了asp代碼塊,並且label type是它最后更改的內容。
為了使它起作用,您可以更改實現它的方式,也許將該代碼隱藏塊編寫為asp塊。
<div class="alert">
<%= Convert.ToInt32(Eval("id")) != 130 ? GetLocalResourceObject("stringType").ToString() : GetLocalResourceObject("intType").ToString() %>
</div>
並將后台代碼更改為
if (id!=130)
{
txtProperty.Attributes.Add("Class", "data_input");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.