Click here to Skip to main content
11,437,816 members (50,117 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 11-Dec-12 1:29am
Comments
Vani Kulkarni at 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 at 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.
shabari7 at 11-Dec-12 7:26am
   
Label lbl = e.Item.FindControl("labelID") as Label;
lbl.Text //
shabari7 at 11-Dec-12 7:27am
   
later pass it as querystring or in session , what ever u are aware of
Skand Pratap Singh at 11-Dec-12 7:48am
   
it is giving error at "Item"?
Skand Pratap Singh at 11-Dec-12 7:50am
   
This is my label,
<asp:Label ID="Label1" runat="server" Text='<%#Eval("regid") %>'>
please elaborate how to use your line of code.
I want to transfer the regid value from this page to other..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

ASPX:

<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:

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.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.150506.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100