Hi I am using asp repeater for list item's speciality textboxes and a div for giving alert textbox type (numeric or string etc) Here is html;
<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>
And here is code behind ;
if (id!=130)
{
txtProperty.Attributes.Add("Class", "data_input");
labelType = GetLocalResourceObject("stringType").ToString();
}
else
{
labelType = GetLocalResourceObject("intType").ToString();
}
Even tho code trigger if and else both, all repeater textboxes take "intType" value which is last item's value. But ;
txtProperty.Attributes.Add("Class", "data_input");
line works fine as I want. Only "labelType" variable problem for me. Thank You
Sorry, but this wouldn't work.
<% %> code blocks are compiled run time after c# code run through. So you change labelType and after that asp code blocks runs and label type is the last thing it changed to.
For it to work you can change the way you implement it, maybe writing that code-behind block to asp block.
<div class="alert">
<%= Convert.ToInt32(Eval("id")) != 130 ? GetLocalResourceObject("stringType").ToString() : GetLocalResourceObject("intType").ToString() %>
</div>
and changing code-behind to just
if (id!=130)
{
txtProperty.Attributes.Add("Class", "data_input");
}