TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Saurabh Bhardwaj
NA
14
14.2k
upade and total in footer templae of repeter not working
Jun 22 2013 6:18 AM
Dear sir,
I have making cart in my project every things went to right but update and total value not working I m also attaching my code ...check and help me as possible.
Soursr Code(HTML)
<asp:Repeater ID="Repeater1" runat="server" onitemcommand="cpRepeater_ItemCommand" >
<HeaderTemplate >
<table width="900px" border="1px">
<tr>
<td>Check</td>
<td>Pic</td>
<td>Product ID</td>
<td>Emailid</td>
<td>Size</td>
<td>Color</td>
<td>Price</td>
<td>Quantity</td>
<td>Cost</td>
<td>Option</td>
</tr>
</HeaderTemplate>
<ItemTemplate >
<tr>
<td><asp:CheckBox ID="CheckBoxDelete" runat="server" /></td>
<td><asp:Label ID="lblid" Visible ="false" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"id") %>' ></asp:Label>
<asp:Image ID ="imagei" runat ="server" Width ="100px" Height ="100px" ImageUrl ='<%# DataBinder.Eval(Container.DataItem,"imagepath") %>' /></td>
<td><asp:Label ID="Label1" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"productid") %>' ></asp:Label></td>
<td><asp:Label ID="emailid" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"emailid") %>' ></asp:Label></td>
<td><asp:Label ID="size" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"ssize") %>' ></asp:Label></td>
<td><asp:Label ID="color" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"color") %>' ></asp:Label></td>
<td><asp:Label ID="price" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"price") %>' ></asp:Label></td>
<td><asp:Label ID="quantity" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"quantity") %>' ></asp:Label>
<asp:TextBox ID="txtName" BackColor="#d4d0c8" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "quantity")%>' Visible="false"></asp:TextBox></td>
<td><asp:Label ID="totalcost" Visible ="true" runat ="server" Text ='<%# DataBinder.Eval(Container.DataItem,"totalcost") %>' ></asp:Label></td>
<td ><asp:LinkButton ID="lnkEdit" runat="server" CommandName="edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>'>Edit</asp:LinkButton>
<asp:LinkButton Visible="false" ID="lnkUpdate" runat="server" CommandName="update" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>'>Update</asp:LinkButton>
<asp:LinkButton Visible="false" ID="lnkCancel" runat="server" CommandName="cancel" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>'>Cancel</asp:LinkButton>
<asp:LinkButton ID="lnkDelete" runat="server" CommandName="delete" OnClientClick='javascript:return confirm("Are you sure you want to delete?")'
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id") %>'>Delete</asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td>
Total
</td>
<td>
<asp:Label ID="lblTotal" runat="server">0</asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:LinkButton ID="dellink" ForeColor="Black" runat="server"
OnClientClick='javascript:return confirm("Are you sure you want to delete?")'
onclick="dellink_Click">Delete Selected</asp:LinkButton>
Client side code(C#)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Caching;
using System.Data.SqlClient;
public partial class shoping : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
int totalPrice = 0;
SqlDataAdapter da;
public static int SQty = 0;
protected void Page_Load(object sender, EventArgs e)
{
username.Text = Request.QueryString["emailid"].ToString();
bindrepeter();
if (Session["emailid"] == null)
{
login.Text = "Login";
}
else
{
login.Text = "Logout";
}
}
//display record//
protected void bindrepeter()
{
SqlCommand cmd = new SqlCommand("select * from cart where emailid='" + username.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "cart");
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
//edit and update record//
protected void cpRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
LinkButton lnkUpdate = (LinkButton)e.Item.FindControl("lnkUpdate");
LinkButton lnkCancel = (LinkButton)e.Item.FindControl("lnkCancel");
LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");
Label totalcost = (Label)e.Item.FindControl("totalcost");
Label price = (Label)e.Item.FindControl("price");
Label lblemailid = (Label)e.Item.FindControl("emailid");
Label lblrptID = (Label)e.Item.FindControl("lblid");
TextBox txtName = (TextBox)e.Item.FindControl("txtName");
CheckBox chkDelete = (CheckBox)e.Item.FindControl("CheckBoxDelete");
if (e.CommandName == "edit")
{
lnkCancel.Visible = true;
lnkUpdate.Visible = true;
lnkEdit.Visible = false;
txtName.Visible = true;
lblemailid.Visible = false;
}
if (e.CommandName == "cancel")
{
bindrepeter();
}
if (e.CommandName == "update")
{
SqlCommand SqlCmd = new SqlCommand("update cart set quantity=@quantity where id=@ID", con);
SqlCmd.Parameters.Add("@quantity", SqlDbType.VarChar).Value = txtName.Text;
SqlCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = e.CommandArgument;
try
{
con.Open();
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
totalPrice = totalPrice + Convert.ToInt32(((Label)e.Item.FindControl("price")).Text);
}
SqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
bindrepeter();
}
if (e.CommandName == "delete")
{
SqlCommand SqlCmd = new SqlCommand("delete cart where id=@ID", con);
SqlCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = e.CommandArgument;
try
{
con.Open();
SqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
bindrepeter();
}
}
void Repeater1_PreRender(object sender, EventArgs e)
{
Label lblTotal = (Label)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("lblTotal");
lblTotal.Text = totalPrice.ToString();
}
protected void dellink_Click(object sender, EventArgs e)
{
foreach (RepeaterItem Item in Repeater1.Items)
{
CheckBox chkDelete = (CheckBox)Item.FindControl("CheckBoxDelete");
Label lblrptID = (Label)Item.FindControl("lblid");
if (chkDelete.Checked)
{
SqlCommand SqlCmd = new SqlCommand("delete cart where id=@ID", con);
SqlCmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = lblrptID.Text;
SqlCmd.Connection = con;
con.Open();
SqlCmd.ExecuteNonQuery();
con.Close();
}
}
bindrepeter();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
Response.Redirect("~/ddorcheque.aspx?emailid=" + username.Text);
}
if (CheckBox2.Checked == true)
{
Response.Redirect("~/cash on delivery.aspx?emailid=" + username.Text);
}
}
protected void sighup_Click(object sender, EventArgs e)
{
if (Session["emailid"] == null)
{
Response.Redirect("userregister.aspx");
}
else
{
Response.Redirect("useraccount.aspx?emailid=" + Session["emailid"].ToString());
}
}
protected void login_Click(object sender, EventArgs e)
{
if (Session["emailid"] == null)
{
Response.Redirect("userlogin.aspx");
}
else
{
Session.Abandon();
Session.Clear();
Response.Redirect("Default.aspx");
}
}
protected void account_Click(object sender, EventArgs e)
{
if (Session["emailid"] == null)
{
Response.Redirect("userlogin.aspx");
}
else
{
Response.Redirect("useraccount.aspx?emailid=" + Session["emailid"].ToString());
}
}
protected void viewcart_Click(object sender, EventArgs e)
{
if (Session["emailid"] == null)
{
Response.Redirect("userlogin.aspx");
}
else
{
Response.Redirect("useraccount.aspx?emailid=" + Session["emailid"].ToString());
}
}
}
Reply
Answers (
0
)
Checking DOB -not entering Future Date
Add Eye-shot application in vb.net form