Click here to Skip to main content
15,887,267 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Add rich text box into web application Pin
venkat86_ece22-Oct-08 4:10
venkat86_ece22-Oct-08 4:10 
GeneralRe: Add rich text box into web application Pin
acroitoriu22-Oct-08 4:20
acroitoriu22-Oct-08 4:20 
QuestionHi all i have a seriou problem plz help me Pin
Member 312887422-Oct-08 3:47
Member 312887422-Oct-08 3:47 
AnswerRe: Hi all i have a seriou problem plz help me Pin
Abhijit Jana22-Oct-08 3:52
professionalAbhijit Jana22-Oct-08 3:52 
AnswerRe: Hi all i have a seriou problem plz help me Pin
Ashfield22-Oct-08 4:15
Ashfield22-Oct-08 4:15 
QuestionUrgent i have a serious problem plz help me Pin
Member 312887422-Oct-08 3:41
Member 312887422-Oct-08 3:41 
AnswerRe: Urgent i have a serious problem plz help me Pin
leckey22-Oct-08 7:24
leckey22-Oct-08 7:24 
QuestionProblem with gridview RowUpdating event Pin
acroitoriu22-Oct-08 3:12
acroitoriu22-Oct-08 3:12 
Hi all,



I have a simple page on which I've place a gridview which is bound to a generic List that contains ShoppingCartItem objects.

the code for my aspx file looks like this:



]]>

<asp:content id="Content3" contentplaceholderid="ArticleContent" runat="server" xmlns:asp="#unknown">
<asp:label id="lblShoppingCartStatus" runat="server" text="">


<asp:gridview onrowediting="gridCart_RowEditing">
OnRowCancelingEdit="gridCart_RowCancelingEdit"
OnRowUpdating="gridCart_RowUpdating"
OnRowCommand="OnRowCommand"
OnRowUpdated="gridCart_RowUpdated"
ID="gridCart" runat="server"
AutoGenerateColumns="false" EnableViewState="true">
<columns> <asp:boundfield readonly="true" datafield="Description" headertext="Product">
HtmlEncode="False">
<itemstyle width="300px">

<asp:boundfield readonly="true" datafield="Price" headertext="Price">
HtmlEncode="False">
<itemstyle width="100px">

<asp:boundfield readonly="false" datafield="Quantity" headertext="Quantity">
HtmlEncode="False">
<itemstyle width="100px">

<asp:commandfield buttontype="Link" edittext="Modify" showeditbutton="true" causesvalidation="false">




My code behind code looks like this:



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


namespace Customer
{
public partial class PrimeShopCheckout : System.Web.UI.Page
{


private List<shoppingcartitem> ShoppingCartItems
{
get
{
if (ViewState["shoppingCartItems"] != null)
{
return (List<shoppingcartitem>)ViewState["shoppingCartItems"];
}
return new List<shoppingcartitem>();
}
set
{
ViewState["shoppingCartItems"] = value;
}
}

private void BindGrid()
{
gridCart.DataSource = ShoppingCartItems;
gridCart.DataBind();
}

protected void gridCart_RowEditing(object sender, GridViewEditEventArgs e)
{
gridCart.EditIndex = e.NewEditIndex;
BindGrid();

}

protected void gridCart_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gridCart.EditIndex = -1;
BindGrid();
}

protected void gridCart_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// get the information
int rowIndex = e.RowIndex;

var a = gridCart.Rows.Count;

}

protected void gridCart_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
e.KeepInEditMode = false;
}

protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
var aaa = gridCart.Rows.Count;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Hashtable shoppingCart = (Hashtable)WebProfile.Current.ShoppingCart;
List<shoppingcartitem> shoppingCartItems = new List<shoppingcartitem>();
IDictionaryEnumerator enumerator = shoppingCart.GetEnumerator();
while (enumerator.MoveNext())
{
var item = new ShoppingCartItem();
Product product = (Product)enumerator.Key;
int quantity = (int)enumerator.Value;
item.Description = product.Description;
item.Price = product.Price;
item.Quantity = quantity;
shoppingCartItems.Add(item);
}
ShoppingCartItems = shoppingCartItems;
gridCart.DataSource = ShoppingCartItems;
gridCart.DataBind();
}
}
}

[Serializable]
public class ShoppingCartItem
{
public string Description { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }

}
}



The problem is that when I click the Update button to change the number of items for a specific product, in the RowUpdating event handler I get the number of rows as 0!!!!

I've read plenty of docs on the gridview, searched google for answers to my problem, saw implementations for the functionality I use .... according to what I read so far, everything should work fine. But it's not!

Can anyone let me know why the number of rows is zero in the row updating event?

Where am I losing the data in the gridview?

I need help with this as I am completly stuck at this moment - I don't have any clue what else to try....



Thanks in advance!



Andrei
QuestionRequired Field Validator in GridView Pin
.NET- India 22-Oct-08 2:59
.NET- India 22-Oct-08 2:59 
QuestionHow to send email from asp.net 2.0 Page help is needed with configuration of SMTP Server Pin
Rameez Raja22-Oct-08 2:08
Rameez Raja22-Oct-08 2:08 
AnswerRe: How to send email from asp.net 2.0 Page help is needed with configuration of SMTP Server Pin
eyeseetee22-Oct-08 2:38
eyeseetee22-Oct-08 2:38 
QuestionStrange JavaScript Pin
Atul Kharecha22-Oct-08 2:00
Atul Kharecha22-Oct-08 2:00 
AnswerRe: Strange JavaScript Pin
NeverHeardOfMe22-Oct-08 2:13
NeverHeardOfMe22-Oct-08 2:13 
GeneralRe: Strange JavaScript Pin
Atul Kharecha22-Oct-08 2:21
Atul Kharecha22-Oct-08 2:21 
QuestionHow can You trap a request come from another website to your website in ASP.net Pin
gautamamit822-Oct-08 1:40
gautamamit822-Oct-08 1:40 
AnswerRe: How can You trap a request come from another website to your website in ASP.net Pin
N a v a n e e t h22-Oct-08 1:59
N a v a n e e t h22-Oct-08 1:59 
Questionthrows an error that the cursor already exists: How to sholve this problem Pin
Member 465900122-Oct-08 1:39
Member 465900122-Oct-08 1:39 
AnswerRe: throws an error that the cursor already exists: How to sholve this problem Pin
N a v a n e e t h22-Oct-08 2:01
N a v a n e e t h22-Oct-08 2:01 
GeneralRe: throws an error that the cursor already exists: How to sholve this problem Pin
Member 465900122-Oct-08 2:14
Member 465900122-Oct-08 2:14 
GeneralRe: throws an error that the cursor already exists: How to sholve this problem Pin
Member 465900122-Oct-08 2:15
Member 465900122-Oct-08 2:15 
GeneralRe: throws an error that the cursor already exists: How to sholve this problem Pin
eyeseetee22-Oct-08 2:37
eyeseetee22-Oct-08 2:37 
AnswerRe: throws an error that the cursor already exists: How to sholve this problem Pin
Paddy Boyd22-Oct-08 2:17
Paddy Boyd22-Oct-08 2:17 
GeneralRe: throws an error that the cursor already exists: How to sholve this problem Pin
Member 465900122-Oct-08 2:34
Member 465900122-Oct-08 2:34 
GeneralRe: throws an error that the cursor already exists: How to sholve this problem Pin
Ashfield22-Oct-08 3:14
Ashfield22-Oct-08 3:14 
QuestionCreating a .txt file in a web form (Urgent) Pin
srinivaskonijeti22-Oct-08 0:13
srinivaskonijeti22-Oct-08 0:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.