How to get the result #Eval ("X") in my C # code?

I have asp code with an object asp:Repeater.

I am familiar with using <%# Eval("field")dataitem.field to print HTML code. However, what should I do if I want to get the result Eval("field")stored in a string literal for further processing?

Update : I feel that I have to apologize for not being more specific. As the first responder suggests, I plan to use the result in ItemTemplate. However, what about the field of the current record, which is not a string? What if I have a complex type containing all kinds of weird ** and I want to refer to fields in my element template, and not as strings?

+3
source share
5 answers

I'm not sure if this is what you are asking for, but if you want to do Evalin a context outside the .aspx markup, you can use DataBinder.Eval directly in your code.

+2
source

To do this, use Server Control:

<asp:Repeater ID="aRepeater" runat="server">
    <ItemTemplate>
        <asp:HiddenField ID="SomeHiddenField" runat="server" value='<%# Eval("FieldID") %>' />
    </ItemTemplate>
</asp:Repeater>

You can get the "FieldID" value later by accessing the "Value" property of the HiddenField control.

+1
source

- , , , . "" # , aspx.

+1

Arief, .

, , .

So, if you have a repeater with a literal in the element template (ltlFieldId), here is how you can access the value stored in the literal:

For Each ri As RepeaterItem In MyRepeater.Items
   Dim ltlFieldId As Literal = ri.FindControl("ltlFieldId")
   Dim FieldId As Integer = CType(ltlFieldId.Text, Integer)
Next
+1
source

Rice,
Have you tried to return the Eval()value that you expect?

0
source

Source: https://habr.com/ru/post/1773937/


All Articles