Link to home
Start Free TrialLog in
Avatar of fosiul01
fosiul01Flag 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
ASKER CERTIFIED SOLUTION
Avatar of PaulsonGeorge
PaulsonGeorge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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

Avatar of PaulsonGeorge
PaulsonGeorge

I think the best way is to trace the flow of the values in run-time.