asp.netvb.netentity-frameworkentity-framework-4entitydatasource

How Can Access Label In Repeater


im try to access label in repeater to get value and set another value in same label

  <ul class="mail-list">
                                        <asp:Repeater ID="repMsg" runat="server" DataSourceID="EDSrepMSg">

                                            <ItemTemplate>
                                                <li>
                                                    <asp:LinkButton ID="lnkMsgDisplay" runat="server" CausesValidation="false" CommandName="Display_Msg" CommandArgument='<%# Bind("message_id") %>'>
                                                        <span class="mail-sender">
                                                            <asp:Label ID="lblEmail" runat="server" Text='<%#Eval("message_from") %>'></asp:Label></span>
                                                        <span class="mail-subject">
                                                            <asp:Label ID="lblSubject" runat="server" Text='<%#Eval("message_title") %>'></asp:Label></span>
                                                        <span class="mail-message-preview">
                                                            <asp:Label ID="lblMsg" runat="server" Text='<%#If (Eval("message_description").ToString.Length > 10,Eval("message_description").ToString.Substring(0,10).TrimEnd() & "..",Eval("message_description"))%>'></asp:Label></span>

                                                    </asp:LinkButton>

                                                </li>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                        <asp:EntityDataSource ID="EDSrepMSg" runat="server" ConnectionString="name=BWJO_dbEntities" DefaultContainerName="BWJO_dbEntities" EnableFlattening="False" EntitySetName="tbl_message"
                                            Where="it.message_to=@message_to and it.message_type=2 or it.message_type=4 " OrderBy="it.message_date desc">
                                            <WhereParameters>
                                                <asp:SessionParameter SessionField="user_id" Name="message_to" Type="Int32" DefaultValue="0" />

                                            </WhereParameters>

                                        </asp:EntityDataSource>

The output:

enter image description here

Note:

Theres no relationship btween tbl_msg,tbl_user,tbl_emp

i want just to know how to get value from

<asp:Label ID="lblEmail" runat="server" Text='<%#Eval("message_from") %>'></asp:Label>

then set value into lblEmail(Edit Label)


Solution

  • you can first get label and then its value, something like this.. for example you have Label:

    <asp:Label ID="lblval" runat="server" Text="this is test"></asp:Label>
    

    then at backend you can get text like:

    protected void rptrMaylike_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label lblv = (Label)e.Item.FindControl("lblval");
            lblv.Text = "Value from code behind";
        }
    }