In this code I am trying to take the control "Label" with ID "Label", this work but also I want to take the current "AuthorUserID" field from Entity Data Source I know i can do this with <%# Eval("AuthorUserID" %>)
but I want to take this field in code behind method, in this case in "ChatListView_ItemDataBound" method.
How to take the current field ("AuthorUserID") in code behind?
Code-behind:
protected void ChatListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
if (e.Item.FindControl("Label") != null)
{
}
}
}
Markup:
<asp:ListView ID="ChatListView" runat="server" DataSourceID="EntityDataSourceUserPosts" OnItemDataBound="ChatListView_ItemDataBound">
<ItemTemplate>
<div class="post">
<div class="postHeader">
<h2><asp:Label ID="Label1" runat="server"
Text= '<%# Eval("Title") + " by " + this.GetUserFromPost((Guid?)Eval("AuthorUserID")) %>' ></asp:Label></h2>
<asp:Label ID="Label" runat="server" Text="" Visible="True"></asp:Label>
<div class="dateTimePost">
<%# Eval("PostDate")%>
</div>
</div>
<div class="postContent">
<%# Eval("PostComment") %>
</div>
</div>
</ItemTemplate>
</asp:ListView>