So, I want to use jquery to set the text of a button, depending on the value of a property in the current row of a repeater.
I need to call a function in the code-behind to map the value to the text the button should have. So, I need to pass to my foo function, the string value of the UserStatus property for the current item in the repeater.
I want to do the following, although this syntax is obviously not correct:
<asp:Repeater ID="dgCustomer" runat="server">
<ItemTemplate>
<input id="rb" name="rb" type="radio" onclick='javascript:$("input.magicbutton").val("<%= foo(DataBinder.Eval(Container.DataItem, "UserStatus")) %>");'
If the codebehind contains the following method definition:
protected string foo(string status)
What is the correct syntax to call foo with an Item value from the repeater?
用<%#切换<%=,看来您应该不错。
The only issue I see with that code snippet is that you need to use a databinding nugget ( <%# ... %>
) instead of the expression nugget ( <%= ... %>
).
You may run into issues with surrounding your nugget with double quotes, since it contains double quotes already. You may have to have foo
return the value in quotes, or even have have foo
just return the whole onclick
event...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.