Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I want to transfer data from a control (e.g. a label control) that is in a repeater control to another page.
I tried using session, but couldn't. Please help with it.
Thank you.
Posted
Comments
Vani Kulkarni 11-Dec-12 6:32am    
Are you able to access the label value which you want to send? If yes and data is of minimal size, try passing value through Query String. Also post the code which you have tried using Session.
Skand Pratap Singh 11-Dec-12 6:51am    
No, i am not able to access the label value because that label is inside the repeater control. And hence I am not able to transfer the data of label control.
[no name] 11-Dec-12 7:26am    
Label lbl = e.Item.FindControl("labelID") as Label;
lbl.Text //
[no name] 11-Dec-12 7:27am    
later pass it as querystring or in session , what ever u are aware of
Skand Pratap Singh 11-Dec-12 7:48am    
it is giving error at "Item"?

You will be required to use either the itemdatabound event or itemCommand event of the repeater, a sample is given below.

ASPX:

ASP.NET
<pre lang="xml"><asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound">
                                <HeaderTemplate>
                                    <table border="0" cellpadding="2" cellspacing="0" width="100%" class="bo">
                                        <tr class="tBg1">
                                            <td align="Center" style="font-size: 18px">
                                                <strong>Heading1</strong>
                                            </td>
                                            <td align="Center" style="font-size: 18px">
                                                <strong>Heading2</strong>
                                            </td>
                                            <td align="Center" style="font-size: 18px">
                                                <strong>Heading3</strong>
                                            </td>
                                            <td align="Center" style="font-size: 18px">
                                                <strong>Heading4</strong>
                                            </td>
                                            <td align="Center" style="font-size: 18px">
                                                <strong>Heading5</strong>
                                            </td>
                                        </tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <tr id="MainRow" runat="Server">
                                        <td class="bor bob" align="left" style="font-size: 18px">
                                            <asp:Label ID="status" runat="server" Text='<%# Eval("status")%>'></asp:Label>
                                        </td>
                                        <td class="bor bob" align="center" style="font-size: 18px">
                                            <a id="lnkCount" runat="server" target="_blank">
                                                <asp:Label runat="server" ID="Labell" Text='<%# Eval("1Count")%>'></asp:Label>
                                            </a>
                                        </td>
                                        <td class="bor bob" align="center" style="font-size: 18px">
                                            <a id="lnkCount24" runat="server" target="_blank">
                                                <asp:Label runat="server" ID="Label1" Text='<%# Eval("2Count")%>'></asp:Label>
                                            </a>
                                        </td>
                                        <td class="bor bob" align="center" style="font-size: 18px">
                                            <a id="lnkCount48" runat="server" target="_blank">
                                                <asp:Label runat="server" ID="Label3" Text='<%# Eval("3Count")%>'></asp:Label>
                                            </a>
                                        </td>
                                        <td class="bor bob" align="center" style="font-size: 18px">
                                            <a id="lnkCount72" runat="server" target="_blank">
                                                <asp:Label runat="server" ID="Label2" Text='<%# Eval("4Count")%>'></asp:Label>
                                            </a>
                                        </td>
                                    </tr>
                                </ItemTemplate>
                                <FooterTemplate>
                                    </table>
                                </FooterTemplate>
                            </asp:Repeater>



CS:

C#
protected void rptDetailed_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
	if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
		HtmlAnchor lnkCount = (HtmlAnchor)e.Item.FindControl("lnkCount");
            HtmlAnchor lnkCount24 = (HtmlAnchor)e.Item.FindControl("lnkCount24");
            HtmlAnchor lnkCount48 = (HtmlAnchor)e.Item.FindControl("lnkCount48");
            HtmlAnchor lnkCount72 = (HtmlAnchor)e.Item.FindControl("lnkCount72");

		Label status = (Label)e.Item.FindControl("status");
	}
}



You need to first find the required control from the repeater item in the event as mentioned in the example.

After that all the above variables can be easily used as regular asp .net controls.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900