Click here to Skip to main content
15,889,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi

i am select the table in grid view openstk,entry stck and totalstack columns

in runtime displays grid default value in openstack column and enter the value in entrystck column in runtime datagrid

what i am expecting in runtime grid resulting in column totalstack = openstack+entrystck

suggest me example for these code

friends anyone clear these calculation method this affects N no of rows i have 175 stock items

thanks
Posted

Hi,

Try using the RowDataBound Event. Use the following code:

C#
protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{   
   //Get data row view
   DataRowView drview = e.Row.DataItem as DataRowView;
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      int value1 = Int32.Parse(e.Row.Cells[0].Text);
      int value2 = Int32.Parse(e.Row.Cells[1].Text);
      e.Row.Cells[2].Text = Convert.ToString(value1+ value2);
   }
}


Hope this helps and gives you an idea :)

Regards,
Praneet
 
Share this answer
 
in DataGridView.CellEndEdit Event[^] calculate and set the totalstack cell value.
Sample code:
C#
int val1 = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
int val2 = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value);
dataGridView1.Rows[e.RowIndex].Cells[2].Value = (val1 + val2).ToString();

refer :[C#]DataGridView howto sum cells[^]
 
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