how could I use the values of the dataGrid
-
Hi all, How could I take the values of cells in the dataGrid and use them outside the dataGrid e.g: i have TimeIn & TimeOut for a certain person during one month (or more or less) i need to calculate the total hours ' in the specified time and view the total in a textBox syntax help (examples) is also needed thank you
-
Hi all, How could I take the values of cells in the dataGrid and use them outside the dataGrid e.g: i have TimeIn & TimeOut for a certain person during one month (or more or less) i need to calculate the total hours ' in the specified time and view the total in a textBox syntax help (examples) is also needed thank you
There are really 2 choices here. You can grab the values out the datagrid, which means you would probably want to use the OnItemDataBound event and calculate the hours for each row as it is added or you can look at the datasource you are providing and get the values from there. For the OnItemDatabound event you can do a case statement like this (this is from memory so forgive me if it isnt exactly correct) -
Select Case e.Item.Type Case Item 'Calculate from cell contents and get a TimeSpan object ts = Convert.ToDateTime(e.Item.Cells(#).Text).Subtract(Convert.ToDateTime(e.item.Cells(#).Text) txtTotalHours = ts.TotalHours End Select
Something along those lines, I hope that helps! Cleako -
Hi all, How could I take the values of cells in the dataGrid and use them outside the dataGrid e.g: i have TimeIn & TimeOut for a certain person during one month (or more or less) i need to calculate the total hours ' in the specified time and view the total in a textBox syntax help (examples) is also needed thank you
Hi, i will try to solve ur problem. The values u entered i mean the employee values that was stored in a table right, again if u want to retrive that values and display on data grid right, if yes means the values u stored in data grid while retriving then create a local variable that supports the perticular data type on which u are operating, with the index of the recordset suppose TimeIn t1 and TimeOut t2 then t2 - t1 for every loop of that perticular employee and keep adding the result to the local variable at last when the record set is empty then assign the value to the textbox out side the grid,I think u may confused but i did it, if u want more information abt this then mail to me :cool:
-
Hi, i will try to solve ur problem. The values u entered i mean the employee values that was stored in a table right, again if u want to retrive that values and display on data grid right, if yes means the values u stored in data grid while retriving then create a local variable that supports the perticular data type on which u are operating, with the index of the recordset suppose TimeIn t1 and TimeOut t2 then t2 - t1 for every loop of that perticular employee and keep adding the result to the local variable at last when the record set is empty then assign the value to the textbox out side the grid,I think u may confused but i did it, if u want more information abt this then mail to me :cool:
-
Hi, i will try to solve ur problem. The values u entered i mean the employee values that was stored in a table right, again if u want to retrive that values and display on data grid right, if yes means the values u stored in data grid while retriving then create a local variable that supports the perticular data type on which u are operating, with the index of the recordset suppose TimeIn t1 and TimeOut t2 then t2 - t1 for every loop of that perticular employee and keep adding the result to the local variable at last when the record set is empty then assign the value to the textbox out side the grid,I think u may confused but i did it, if u want more information abt this then mail to me :cool:
-
how could I convert a value in the dataGrid to string in order to use it outside the grid?
You either need to do something like OnItemDataBound because that will let you access each row or you will need to know the row index and cell number in order to access the .Text property which returns a string. I have found that many times though it will return a
& nbsp;
(spaced so it will show up) value so I almost always do a.Text.Replace("& nbsp;", "")
on the value to make sure I dont have that HTML space. Check out http://www.datagridgirl.com/[^], there you will find many datagrid answers. Cleako