Click here to Skip to main content
15,943,061 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi sir,


Project: Online shopping

Task: shopping cart

I want show the shopping cart details in gridview but I want edit, update and remove items in grid view please send the coding path in asp.net

I search the website also, but still am doing same process. please help me.



By

Bala
Posted

1 solution

In a grid view,

C#
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound"
ShowFooter="True" AllowPaging="True" PageSize="5"
BackColor="#ffffff" BorderColor="AliceBlue"
BorderStyle="None" BorderWidth="1px"
CellPadding="3"
CellSpacing="2" FooterStyle-BackColor="#da821e"
FooterStyle-ForeColor="#ffffff"
RowStyle-BackColor="#003366"
RowStyle-ForeColor="#ffffff"
AlternatingRowStyle-BackColor="#da821e">
<columns>
<asp:boundfield datafield="ID" headertext="ID">
InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:boundfield datafield="Name" headertext="Name">
InsertVisible="False" ReadOnly="True"
SortExpression="Name" FooterText="Total"/>
<asp:templatefield headertext="Amount">
<itemtemplate>
<asp:label id="lblAmount" runat="server">
Text='<%# "$"+Eval("Amount").ToString()%>'>
</asp:label>
</itemtemplate>
<footertemplate>
<asp:label id="lblTotal" runat="server"></asp:label>
</footertemplate>
</asp:templatefield>
</asp:boundfield></asp:boundfield></columns>
<pagerstyle forecolor="#8C4510" horizontalalign="Center" />
<headerstyle backcolor="#da821e" font-bold="True">
ForeColor="White" />
</headerstyle></asp:gridview>
<asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Amount] FROM [Expenses]">
</asp:sqldatasource>

<pre lang="text">

in aspx page
C#
public partial class _Default : System.Web.UI.Page
{
decimal grdTotal = 0;
protected void Page_Load(object sender, EventArgs e)
{

}
.protected void GridView1_RowDataBound
(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal rowTotal = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, "Amount"));
grdTotal = grdTotal + rowTotal;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl = (Label)e.Row.FindControl("lblTotal");
lbl.Text = grdTotal.ToString("c");
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900