Avatar of fosiul01
fosiul01
Flag for United Kingdom of Great Britain and Northern Ireland asked on

How to use Repeater Control and Session variable to pass value from page to page

Hi, Currently i am using repeater to show all the data from database. and when some one will click on data it will take to anohter page by using query string.

but is there any way to use Session with repeater control ?? ( i dont want to use query string for exposing data)
here currently i am using this code :

<asp:Repeater ID="Repeater2" runat="server" DataSourceID="ObjectDataSource2">
        <HeaderTemplate><ul></HeaderTemplate>
        <ItemTemplate>
<li><a href="showknowledgecategory.aspx?Id=<%# DataBinder.Eval (Container.DataItem, "catid") %>"><%#DataBinder.Eval(Container.DataItem, "cat_Name")%></a></li>
             
       </ItemTemplate>
        <FooterTemplate></ul></FooterTemplate>
    </asp:Repeater>

Thanks for advise
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
PaulsonGeorge

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
PaulsonGeorge

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
fosiul01

ASKER
HI, thanks, i almost did what you said, but there is one problem

I have attached the code , here i am trying to get the session value in a textbox from another page

Problem is : i need to click 2 times to set the session value, dont know why

suppose : after running the programm -
when i am cliking on link1 , textbox is showing link1

now when i am clicking on link2 - text box is still showing link1

i will have to click on link2 again to set the session value for link2!!!!

why its happening ??




page1.aspx -------------
asp:Repeater ID="Repeater3" runat="server" DataSourceID="ObjectDataSource2" OnItemCommand="Repeater3_ItemCommand" >
        <HeaderTemplate><ul></HeaderTemplate>
        <ItemTemplate>
              	
        <li>   <asp:LinkButton ID="catid" runat="server" Visible="true" text='<%# DataBinder.Eval (Container.DataItem, "cat_Name") %>' > </asp:LinkButton> </li>
            
        </ItemTemplate>
        <FooterTemplate></ul></FooterTemplate>
    </asp:Repeater>    
 
page1.vb :
 
 Protected Sub Repeater3_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles Repeater1.ItemCommand, Repeater3.ItemCommand
 
 
        Session("mycat") = CType(Repeater3.Items(e.Item.ItemIndex).FindControl("catid"), LinkButton).Text
 
    End Sub
 
page2.vb :
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Session("mys") = "fosiul"
        If IsPostBack Then
 
            TextBox1.Text = Session("mycat")
        End If
 
 
    End Sub

Open in new window

PaulsonGeorge

I think the best way is to trace the flow of the values in run-time.
Your help has saved me hundreds of hours of internet surfing.
fblack61