asp.net eval issue
So I have a asp.net page with a repeater bound to a viewmodel
I want to show/hide a block of HTML based on if the current row property CapAssignedToUserCode is the same as the variable currentUserCode (see if statement)
there is a开发者_如何学C value in the current row for the property CapAssignedToUserCode and if I hardcode the Eval("CapAssignedToUserCode") to a string it all works
I basically want to get the current row of the repeater and pass the property CapAssignedToUserCode to the function commonCap.SameUserCode
<asp:Repeater ID="rptAnnualActionsAssigned" runat="server">
<ItemTemplate>
<div class="item">
<asp:HiddenField ID="hdnCapItemId" runat="server" />
<h4>
<%#Eval("CategoryTitle")%>:
<%#Eval("CategoryIndex")%></h4>
<span class="status"><strong>Status: </strong>
<%#Eval("CapAssignedStatus")%></span>
<span class="status"><strong>Assigned To: </strong>
<%#Eval("CapAssignedToFullname")%></span>
<div class="noHighlightTable">
usercode:<%#Eval("CapAssignedToUserCode")%>
<%
if (showCompleteBtn || commonCap.SameUserCode(Eval("CapAssignedToUserCode").ToString(), currentUserCode))
{%>
<a class="noHighlightBtn" onclick="OpenSPDialog('/_layouts/beim/CAPAction.aspx?capDataId=' + <%#Eval("CapDataId")%>, 'Complete Action')"
href="javascript:void(0);">Complete action</a>
<%
}%>
Use Eval only to render field, if you want to pass field data to method use Container.DataItem.
So your code should looks like that:
<%#
if (showCompleteBtn || commonCap.SameUserCode((Container.DataItem as YourBindedType).CapAssignedToUserCode), currentUserCode))
{%>
Call a method inline. The method has your logic/output.
<%# WhateverYourLogicIs( (bool) DataBinder.Eval(Container.DataItem,"CapAssignedToUserCode") ) %>
There are several other ways including checking the eval directly. Check out:
Conditional Logic in ASP.net page
精彩评论