Mian Sahib Jan 0 Newbie Poster

i have a repeater in one page to which me load the data from database now i want to click a button and i get the value of a repeater specific row data and kept data in session and access that data an another page.plz help me any one have any idea or any simple code.
i will be very thank full for yours this kindness.
YOur sinser Regard Mian sahib Jan .
me have the following code.now i to access these value from a repeater and keep it in session.
/////

<asp:Repeater ID="Repeater1" runat="server" >
``
                                <table border="1" width="100%">
                            <tr>
                            <th>ItemImage</th>
                            <th>Item Name</th>
                            <th>Item Price </th>
                             <th>Quantity</th>                 
                            </tr>
                    </HeaderTemplate>
          <ItemTemplate>
              <tr><td>
                <asp:Image ID="imgBooks" runat="server" Width="220px" Height="180px" ImageUrl='<%# Bind("ItemImage", "~/ImageStorage/{0}") %>' style="padding-left:40px"/><br />
                </td>

                  <td>
                <asp:Label ID="lblBookName" runat="server" Text='<%# Bind("ItemName") %>'></asp:Label>
                  </td>


                  <td>
                <asp:Label ID="lblPrice" runat="server" Text='<%# Bind("ItemPrice") %>'></asp:Label>
                      <br />
                      <br />

                       <button type="button" id="btnAddItem" value="" class="btn   btn-danger" >
                   <span class="glyphicon glyphicon-shopping-cart"></span>Add Item </button>

              </td>


                  <td>
                <asp:Label ID="lblCity" runat="server" Text=' <%# Bind("ItemQuantity") %>'></asp:Label>

                      </td>
              </tr>
          </ItemTemplate>
                       <FooterTemplate>
                    </table>
                    </FooterTemplate>
        </asp:Repeater>
        ///
        back end code/////
         protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BindData();
        }
    }
    protected void BindData()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["strcon"].ConnectionString);
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        DataSet ds = new DataSet();
        string Query = "Select * from Items where Category=1";

        SqlCommand cmd = new SqlCommand(Query, con);

        SqlDataAdapter adp = new SqlDataAdapter(cmd);

        adp.Fill(ds);

        Repeater1.DataSource = ds.Tables[0];

        Repeater1.DataBind();

    }


}

Dani AI

Generated

As ’s markup shows, the plain HTML <button> will not post back to the server. The usual, robust pattern is: make the Add button a server control (Button/LinkButton) with a CommandName and CommandArgument (the item ID), handle Repeater.ItemCommand in the code‑behind, and maintain a small cart DTO list in Session (ID, name, price, qty). That keeps the session small, avoids storing entire DataSets, and makes the cart easy to consume on the other page.

[Serializable]
public class CartItem
{
    public int ItemId { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
}

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "Add")
    {
        int id = Convert.ToInt32(e.CommandArgument);
        CartItem item = GetItemFromDatabase(id); // lightweight SELECT ItemName, ItemPrice
        var cart = Session["Cart"] as List<CartItem> ?? new List<CartItem>();
        var existing = cart.FirstOrDefault(x => x.ItemId == id);
        if (existing != null) existing.Quantity += 1;
        else { item.Quantity = 1; cart.Add(item); }
        Session["Cart"] = cart;
    }
}

On the destination page the cart is retrieved and cast back:

var cart = Session["Cart"] as List<CartItem>;
if (cart != null)
{
    foreach (var ci in cart)
    {
        // render ci.Name, ci.Price, ci.Quantity
    }
}

Notes and troubleshooting: ensure the cart class is [Serializable] if the app uses StateServer or SQLServer session. Keep what’s stored in Session minimal (IDs + qty preferred); avoid large DataSets or images. If markup isn’t wired, add OnItemCommand or wire the event in Page_Init. When taking values from controls, prefer CommandArgument (ID) and re-query for price/name to avoid trusting client HTML. For load‑balanced environments use sticky sessions or centralized session storage, and always check Session["Cart"] for null before using it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.