Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone help?

in which event we should call this method for binding this value out of the grid view?

description:
consider we have two rows in gridview...that gridview has price & quanyiy..here quantity is editable one...when i click edit it is updated but it is not showing on out of grid...only the last row had shown..but some other rows in gridview not shows............pls help if anyone know..
C#
public void total()
    {
        float price1,totalprice;
        int quantity1;
        foreach (GridViewRow row in GridView1.Rows)
        {
            int pro_id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex][0]);
             price1 = dal.getprice(pro_id);
            quantity1 = dal.getquantity(pro_id);
             totalprice = quantity1*price1;
            lbltprice.Text = totalprice.ToString();
        }
    }
Posted
Updated 6-Dec-11 23:03pm
v2
Comments
[no name] 7-Dec-11 5:04am    
EDIT: added "pre" tag
Al Moje 8-Dec-11 0:04am    
Hi,
Advised you to manipulate the changes rather updates in your grid DataSource, then rebind it in your grid. as i see in your code surely 'You are updating the last row in your grid'...

1 solution

Al is right.
On the rebinding of your grid the calculated values will be lost as the data is refetched from the data source.
Therefore you need to keep some sort of dictionary of the data you have "collected" ie the quantity variables associated with a key value from the grid.

Then fetch your source data, loop through the objects find the ones that have your key values and update the datasource and rebind.
 
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