repeater selected row should display in grid view without postback

Posted by Ashok707 under ASP.NET on 8/30/2012 | Points: 10 | Views : 2283 | Status : [Member] | Replies : 4
hi all,
This is my first post in .net funda.

My query is that i am doing a shopping cart site.I have a repeater control loaded with products and when user clicks on a specific product ,the selected product should get loaded to the gridview which is at the rightcorner .It should happen without postback and when user selects another product the gridview should get updated with another product.How to attain the result. Expecting ur suggestions.
Thank you

ashok


Responses

Posted by: Fahadullah1 on: 10/30/2012 [Member] Starter | Points: 25

Up
0
Down
I have the same issue.
Please let me know if u have got some solution.

Ashok707, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/30/2012 [Member] Starter | Points: 25

Up
0
Down
hi to all,

To attain the data dynamically you have to use the Session (concept of state management) for this, the following steps will help you to perform the action..

1) declare the datatable and add columns according to your requirement.

2) when click event perform for the selected product then get the selected values of the product and add it to the datatable

3) store the datatable into the Session variable

4) bind the datatable to the gridview.

5) now, if user further click on any of product, then firstly get the values from the Session variable to the datatable, and then add new row to the datatable, then repeat step 3 and 4.

Hopefully, it will helpfull to do so. Also, it has no impact with postback whether page will postback or not.

If you dont want to do postback while performing the operation then do use Ajax or Anthem.

Sourabh07

Ashok707, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Fahadullah1 on: 10/30/2012 [Member] Starter | Points: 25

Up
0
Down
Could you please send me some code snippt ??


Ashok707, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/31/2012 [Member] Starter | Points: 25

Up
0
Down
hi....

try this.....and modify it accordingly......:-)

Design Page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sc" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email Id
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btn" Text="Add" runat="server" OnClick="btn_Click" />
</td>
</tr>
<tr>
<td colspan="2">
Added List
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="gv" runat="server">
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


Code File :

using System;

using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGrid();
}

protected void btn_Click(object sender, EventArgs e)
{
BindGrid();
txtEmail.Text = "";
txtName.Text = "";
}

void BindGrid()
{
DataTable dt;

if (Session["Table"] == null)
{
dt = new DataTable("Table");
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Email-Id", typeof(string));


}
else
dt = (DataTable)Session["Table"];



DataRow dr = dt.NewRow();

dr[0] = txtName.Text;
dr[1] = txtEmail.Text;

if (txtName.Text != "" && txtEmail.Text != "")
{
dt.Rows.Add(dr);
}

Session["Table"] = dt;

gv.DataSource = dt;
gv.DataBind();
}
}




Sourabh07

Ashok707, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response